【问题标题】:Storing Image in wrong direction以错误的方向存储图像
【发布时间】:2014-12-15 14:22:36
【问题描述】:

以纵向模式拍摄的图像将保存为横向。但是以横向模式拍摄的图像可以正确保存。

private class SaveImageTask extends AsyncTask<byte[], Void, Void> {
    @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.
    }
}

【问题讨论】:

    标签: android


    【解决方案1】:

    一些 Android 相机硬件会在横向创建纵向图像,JPEG 文件中的 EXIF 标头指示图像查看器应该旋转图像。

    一些 Android 相机硬件会将肖像图像创建为肖像。

    对此您无能为力。欢迎您扫描生成的 JPEG 以查找 EXIF 标头并自行旋转图像,但这很慢且占用大量内存。

    【讨论】:

    • 感谢您的快速回复。如果您在保存到画廊之前帮助我旋转图像,我将更加感激。在保存到图库之前,我还需要处理图像的纵横比。
    • 这里是旋转eventuallyconsistent.net/2011/07/21/…的教程
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2019-11-27
    相关资源
    最近更新 更多