在错误的方向上存储图像图像、错误

2023-09-03 22:12:31 作者:感动是毒心软是病

图片您可以在纵向模式将被保存在的景观。但在横向模式拍摄的图像被正确保存。

私有类SaveImageTask扩展的AsyncTask {

@覆盖    保护无效doInBackground(字节[] ...数据){

 的FileOutputStream outStream = NULL;
    INT旋转= 0;
    尝试 {
    文件SD卡= Environment.getExternalStorageDirectory();
    文件DIR =新的文件(sdCard.getAbsolutePath()+/ SELFie);
    dir.mkdirs();
    字符串文件名=的String.Format(%D.JPG,System.currentTimeMillis的());

    //保存到文件之前旋转为纵向,并保存在一个合适的比例。

文件不过outFile =新的文件(目录,文件名);
    Log.d(SaveImageTask,这是一个输出媒体文件);
    outStream =新的FileOutputStream(将String.valueOf(不过outFile));
    Log.d(SaveImageTask,OutStream);

      //将数据写入到文件中

outStream.write(数据[0]);
    Log.d(SaveImageTask,将数据写入到outStream);
    outStream.flush();

    Log.d(SaveImageTask,OutStream.flush);
    outStream.close();

    Log.d(SaveImageTask,关闭outStream);
    Log.d(DEBUG_TAG,onPictureTaken  - 写字节:+ data.length +至+ outFile.getAbsolutePath());

     //刷新库保存最近拍摄的照片。

     refreshGallery(不过outFile);

     //调用refreshGallery方法之后。

    }赶上(FileNotFoundException异常E){
     e.printStackTrace();

    }赶上(IOException异常E){
     e.printStackTrace();

    } 最后 {
    }
    返回null;

     //最后返回空。
     }
    }
 

解决方案

一些Android摄像头的硬件将创建横向纵向图像,与JPEG文件,表明图像浏览器应旋转图像的EXIF头。

一些Android摄像头硬件会产生纵向图像人像。

还有就是你真的可以做这个没什么。欢迎您扫描所产生的JPEG的EXIF头和自己旋转图像,但这是缓慢和内存密集型的。

Image take in portrait mode will be saved in the landscape. But images taken in the landscape mode is saved correctly.

如何解决PS内存不足无法存储的错误提示情况

private class SaveImageTask extends AsyncTask {

@Override protected Void doInBackground(byte[]... data) {

    FileOutputStream outStream = null;
    int rotate = 0;
    try {
    File sdCard = Environment.getExternalStorageDirectory();
    File dir = new File(sdCard.getAbsolutePath() + "/SELFie");
    dir.mkdirs();
    String fileName = String.format("%d.jpg", System.currentTimeMillis());

    // Before saving to the file rotate to portrait and save it in a right ratio.

File outFile = new File(dir, fileName);
    Log.d("SaveImageTask","It is a OutPut media file");
    outStream = new FileOutputStream(String.valueOf(outFile));
    Log.d("SaveImageTask","OutStream");

      // writing data to the file

outStream.write(data[0]);
    Log.d("SaveImageTask","writing the data to the outStream");
    outStream.flush();

    Log.d("SaveImageTask","OutStream.flush");
    outStream.close();

    Log.d("SaveImageTask","closing the outStream");
    Log.d(DEBUG_TAG, "onPictureTaken - wrote bytes: " + data.length + " to " +       outFile.getAbsolutePath());

     // Refreshing the gallery to save recently taken photos.

     refreshGallery(outFile);

     // After calling the refreshGallery method.

    } catch (FileNotFoundException e) {
     e.printStackTrace();

    } catch (IOException e) {
     e.printStackTrace();

    } finally {
    }
    return null;

     // Finally returning the null.
     }
    }

解决方案

Some Android camera hardware will create portrait images in landscape, with an EXIF header in the JPEG file indicating that the image viewer should rotate the image.

Some Android camera hardware will create portrait images as portrait.

There is nothing that you can really do about this. You are welcome to scan the resulting JPEG for the EXIF header and rotate the image yourself, but this is slow and memory-intensive.