sgarman sgarman - 2 months ago 49x
Android Question

Exif data TAG_ORIENTATION always 0

I need to know the orientation of an image from the gallery (taken by the camera). My initial approach was to use MediaStore.Images.Media.ORIENTATION which was working for my Droid 1. While testing on the HTC Thunderbolt that phone only saves 0 to that field.

I then moved to reading the exif data:

ExifInterface exifReader = new ExifInterface(mFilePath);
exifReader.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);

This also returns 0 for every image. Anyone have ideas on how to properly get the orientation of a photo take on android?


My solution:

Remove any checking for orientation from exif data. I could not find one instance where it was accurate.

Use the standard String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION}; to get an orientation.

If this is 0 use decodeStream...

if(o.outHeight > o.outWidth){
  //set orientation to portrait

else it is landscape