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 m
Here is the code I used onActivityResult() in my activity. The intent returned was for picking an image of the type image/*. Works well for me!
Uri imageUri = intent.getData();
String[] orientationColumn = {MediaStore.Images.Media.ORIENTATION};
Cursor cur = managedQuery(imageUri, orientationColumn, null, null, null);
int orientation = -1;
if (cur != null && cur.moveToFirst()) {
orientation = cur.getInt(cur.getColumnIndex(orientationColumn[0]));
}
Matrix matrix = new Matrix();
matrix.postRotate(orientation);
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
This is a bug i found that was related to another android bug.. I found a reasonable solution posted here https://stackoverflow.com/a/8864367/137404