Disable Android image auto rotate

前端 未结 1 401
感情败类
感情败类 2021-01-27 01:26

When I\'am selecting image from gallery and showing the image in ImageView some of the images is auto rotated with 90 degrees.

How do I disable this?

Co

相关标签:
1条回答
  • 2021-01-27 01:45

    You should rotate this images yourself. Read image orientation value from content provider, specifically Images.Media.ORIENTATION field and rotate it correspondingly.

    This images are stored rotated. Rotate angle is saved in media database.

    public int getOrientation(Uri selectedImage) {
        int orientation = 0;
        final String[] projection = new String[]{MediaStore.Images.Media.ORIENTATION};      
        final Cursor cursor = context.getContentResolver().query(selectedImage, projection, null, null, null);
        if(cursor != null) {
            final int orientationColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.ORIENTATION);
            if(cursor.moveToFirst()) {
                orientation = cursor.isNull(orientationColumnIndex) ? 0 : cursor.getInt(orientationColumnIndex);
            }
            cursor.close();
        }
        return orientation;
    }
    

    You can rotate image using ImageView.setImageMatrix() for example.

    0 讨论(0)
提交回复
热议问题