Android - when getting images from Gallery, portraid images come back as landscape (rotated 90 degrees)

StackOverflow https://stackoverflow.com/questions/4297620

  •  28-09-2019
  •  | 
  •  

Question

Android - when getting images from Gallery, they are with wrong orientation.

For example, if they are landscape images, they are ok, but if they are portrait, they are rotated 90 degrees and again shown as landscape.

This is how I start the activity for picking images:

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");

And when I get the path, this is how I decode the image:

    userPic = BitmapFactory.decodeFile(path);

How can I workaround/fix this issue? Is there anything I am doing wrong?

Was it helpful?

Solution

My guess is that the images are correctly being displayed as they are stored but they have EXIF data saying that the orientation should be rotated 90 degrees. If you're building your app for Android 2.0 and above, take a look at the ExifInterface class. If you're targeting earlier versions of Android, take a look at this answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top