Android Save Image Exif信息在Marshmallow 6.0.1中出错

Aja*_*pal 20 android exif image orientation

在我的自定义相机中,我需要保存捕获图像的方向.此代码适用于其他Android版本.但它不适用于6.0.1.将属性保存到图像文件后,得到的结果是错误的.

try {
    exif = new ExifInterface(pictureFile.getAbsolutePath());
    exif.setAttribute(ExifInterface.TAG_ORIENTATION, "" + orientation);
    exif.saveAttributes();
} catch (IOException e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

小智 1

尝试此方法来保存捕获图像的不同角度的方向:-

Options options = new Options();

// downsizing image as it throws OutOfMemory Exception for larger
// images

        options.inSampleSize = 8;
    ExifInterface exif;
    try {
        exif = new ExifInterface(fileUri.getPath());

        int orientation = exif.getAttributeInt(
                ExifInterface.TAG_ORIENTATION, 0);
        Log.d("EXIF", "Exif: " + orientation);
        Matrix matrix = new Matrix();
        if (orientation == 6) {
            matrix.postRotate(90);
            Log.d("EXIF", "Exif: " + orientation);
        } else if (orientation == 3) {
            matrix.postRotate(180);
            Log.d("EXIF", "Exif: " + orientation);
        } else if (orientation == 8) {
            matrix.postRotate(270);
            Log.d("EXIF", "Exif: " + orientation);
        }

        myBitmap = BitmapFactory.decodeFile(path_img, options);

        myBitmap = Bitmap.createBitmap(myBitmap, 0, 0,
                myBitmap.getWidth(), myBitmap.getHeight(), matrix,
                true);

    } catch (Exception e) {

    }
Run Code Online (Sandbox Code Playgroud)