I use this image cropping library and it crops images as desired but I can't get it to read exif data to be used for rotation. I keep getting the file not found exception though read and write external permissions are set in the manifest file. Here's how the I attempt to read exif data
public static int getExifRotation(File imageFile) {
if (imageFile == null) return 0;
try {
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
// We only recognize a subset of orientation tag values
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) {
case ExifInterface.ORIENTATION_ROTATE_90:
return 90;
case ExifInterface.ORIENTATION_ROTATE_180:
return 180;
case ExifInterface.ORIENTATION_ROTATE_270:
return 270;
default:
return ExifInterface.ORIENTATION_UNDEFINED;
}
} catch (IOException e) {
Log.e("Error getting Exif data", e);
return 0;
}
}
And here's the logcat response
E/android-crop: Error getting Exif data
java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/20180610_014252.jpg: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at android.support.media.ExifInterface.<init>(ExifInterface.java:1300)
at com.nextgen.cropping.CropUtil.getExifRotation(CropUtil.java:52)
I even changed
imageFile.getAbsolutePath()
to
imageFile.getPath()
and it doesn't work. CropUtil.java:52 reffers to this line
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());