0

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());
Vine
  • 46
  • 9
  • It is unclear what the file where you want the exif from has to do with anything that is or has to be cropped. How can a library crop this file if it cannot even read the file? – greenapps Jun 12 '18 at 15:49
  • Yes it claims not to read the file but it does. My problem is it rotates images and i want all images to be in portrait mode – Vine Jun 12 '18 at 16:00
  • Are you asking permissions in manifest? For Android 6+: did you add runtime permission code? – greenapps Jun 12 '18 at 16:22
  • as mentioned in the question manifest permissions are set. I don't know how to implement runtime permission codes. Please help – Vine Jun 12 '18 at 22:05
  • Then google for. Your problem has been mentioned a hundred times already. – greenapps Jun 13 '18 at 07:12

0 Answers0