0

I'm having an endless problem with camera intent captured image using various devices and for some devices neither the ExifInterface nor using contentresolver mentioned here solve my issue :

Why does an image captured using camera intent gets rotated on some devices on Android?

regarding ExifInterface in some devices it always returns ExifInterface.undefined (zero) . and as for content resolver when i query for the orientation i also get zero which is sometimes also not correct.

specifically i used user2832184 answer here :

How can i find the orientation of a picture taken with Intent MediaStore.ACTION_IMAGE_CAPTURE?

any other solutions suggested ?

i need the native camera app full functionality so i can not switch to camera api and build everything from scratch .

also i don't mind using third party solutions to solve this issue.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
user2469133
  • 1,940
  • 3
  • 21
  • 33

3 Answers3

2

If the image lacks the orientation header, there is nothing much you can do about that. Some devices (e.g., HTC M7 GPE) have messed-up firmware that fails to encode the orientation header in the JPEG. However, other devices will be encoding the image properly, and it just happens to be in the proper orientation, so there is no need for the header. There is no good way to programmatically distinguish these cases, other than via a hard-coded list of devices that are giving you trouble.

Even for those hard-coded devices, you have a problem: technically, you do not know what the right orientation is. The user may have entered the camera app from your app, rotated the device, taken a picture, rotated the device back to its original orientation, and only then return to your app.

Your choices are:

  1. Ignore the problem entirely.

  2. Ignore the problem, but give the user some ability to manually request that you rotate the image.

  3. Have the hard-coded list of devices that are exhibiting problems, and warn the user about the issue at an appropriate point.

  4. Have the hard-coded list of devices that are exhibiting problems, and if the user takes a picture on one of those devices, assume that the orientation of the device when control returns to you is the orientation of the device from when the user took the picture. Then, rotate the image as needed.

None of these will be perfect solutions.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Also, some devices have a specific bug that the EXIF header, while saved in the Gallery, is not copied to the image returned for **EXTRA_OUTPUT**. See *[Images taken with ACTION_IMAGE_CAPTURE always returns 1 for ExifInterface.TAG_ORIENTATION on some Gingerbread devices](https://stackoverflow.com/questions/8450539/images-taken-with-action-image-capture-always-returns-1-for-exifinterface-tag-or)*. – Alex Cohn Oct 13 '18 at 12:24
0

The accepted answer here: Controlling the camera to take pictures in portrait doesn't rotate the final images Worked for me, so if anyone stumbles on this, you might want to check it out. (get the EXIF orientation attribute and rotate the image accordingly)

Steelight
  • 3,347
  • 1
  • 20
  • 17
0

You can use the Glide Library:

Glide.with(this).load(image_uri).into(productIconIv);

where image_uri is your image URI and productIconIv is an ImageView

Ryan M
  • 18,333
  • 31
  • 67
  • 74