读取Exif数据android图像裁剪器时出错

时间:2018-06-12 14:45:16

标签: android file orientation exif

我使用this图像裁剪库并根据需要裁剪图像,但我无法读取exif数据以用于旋转。尽管读取和写入外部权限已在清单文件中设置,但我仍然一直收到文件未找到异常。  以下是我尝试读取exif数据的方法

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;
    }
}

这里是logcat响应

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)

我甚至改变了

imageFile.getAbsolutePath()

imageFile.getPath()

并且它不起作用。 CropUtil.java:52引用此行

ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());

0 个答案:

没有答案