Skip to content

Instantly share code, notes, and snippets.

@nuuneoi
Created June 12, 2016 11:09
Show Gist options
  • Save nuuneoi/16e8ecb356af1054412c82eafcb70ba7 to your computer and use it in GitHub Desktop.
Save nuuneoi/16e8ecb356af1054412c82eafcb70ba7 to your computer and use it in GitHub Desktop.
class BitmapUtils {
public static int getRotationFromFileUri(Context context, Uri contentUri) {
String filepath = contentUri.getPath();
ExifInterface exifData = null;
try {
exifData = new ExifInterface(filepath);
int orientation = exifData.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
return exifToDegrees(orientation);
} catch (IOException e) {
} catch (IllegalArgumentException e) {
} catch (Exception e) {
}
return 0;
}
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment