3

When capturing a photo via the MediaStore.ACTION_IMAGE_CAPTURE intent, the preview displayed is in wrong orientation. This only happens on a few devices. Attached is the screenshot of how it looks. Photo was taken with the front cam on portrait. Our app already handles the orientation correction, so when user taps check, it is in the correct orientation. The problem is really just the preview.

Tried using i.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);, but it's not working. Is there any way to solve this? Or do I have to implement a custom camera?

EDIT: The preview i meant is the one shown after you capture a photo and before you select/finalize the photo you've captured. On our scenario (as shown on the screenshot attached, onActivityResult() is not yet called. Tapping the check button is what calls the onActivityResult() callback.

Taken with the front cam on portrait

Community
  • 1
  • 1
PenguinBlues
  • 308
  • 5
  • 15

1 Answers1

1

Most phone cameras are landscape, meaning if you take the photo in portrait, the resulting photos will be rotated 90 degrees. In this case, the camera software should populate the EXIF data with the orientation that the photo should be viewed in. I copy this answer from here

Other way, you can get rotation from camera then do whatever you want to returned image. Full code here This sample about image picker, but the code handling image returned help me control rotation of image.

private int getRotationFromCamera(Context context, Uri imageFile) {
        int rotate = 0;
        try {

            context.getContentResolver().notifyChange(imageFile, null);
            ExifInterface exif = new ExifInterface(imageFile.getPath());
            int orientation = exif.getAttributeInt(
                    ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);

            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotate = 270;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotate = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotate = 90;
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rotate;
    }
Community
  • 1
  • 1
Fuyuba
  • 191
  • 1
  • 8
  • Actually, we don't have a problem correcting the resulting photo to the proper orientation because onActivityResult, we determine the rotation similar to the method in your answer. The problem is with the MediaStore.ACTION_IMAGE_CAPTURE intent (whatever camera app it launches, i have no idea), which displays its preview the wrong way. The preview i meant is the one shown after you capture and before you select/finalize the image you've captured. – PenguinBlues Jun 22 '16 at 03:45
  • After captured, you can check the image stored temporarily. Does the image have true orientation? – Fuyuba Jun 22 '16 at 04:34