android front and back camera captured picture orientation issue, rotated in a wrong way

后端 未结 5 1301
一整个雨季
一整个雨季 2021-02-05 10:12

I have a camera app in portrait mode which takes pictures from both front and back end cameras.The issue is like the captured images are rotated in a wrong way...

For pr

5条回答
  •  花落未央
    2021-02-05 10:55

    I'm using the following code for this:

    ExifInterface exif = new ExifInterface(getUriPath(uri));
    int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);
    

    getUriPath:

    public String getUriPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, projection, null, null,
                null);
        if (cursor != null) {
            int column_index = cursor.getColumnIndexOrThrow(projection[0]);
            cursor.moveToFirst();
            String filePath = cursor.getString(column_index);
            cursor.close();
            return filePath;
        } else
            return null;
    }
    

提交回复
热议问题