Created
June 12, 2016 11:09
-
-
Save nuuneoi/16e8ecb356af1054412c82eafcb70ba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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