0

从 Android Studio 中的 Android Emulator 捕获图像后,我得到一个内容 URI,并通过它处理图像。其中一个过程是我想修改方向。所以我有一个功能可以做到这一点

@Throws(IOException::class)
    fun modifyOrientation(bitmap: Bitmap, imagePath: String): Bitmap {
        val ei = ExifInterface(File(imagePath).absolutePath)

        return when (ei.getAttributeInt(
            ExifInterface.TAG_ORIENTATION,
            ExifInterface.ORIENTATION_NORMAL
        )) {
            ExifInterface.ORIENTATION_ROTATE_90 -> rotate(bitmap, 90L.toFloat())

            ExifInterface.ORIENTATION_ROTATE_180 -> rotate(bitmap, 180L.toFloat())

            ExifInterface.ORIENTATION_ROTATE_270 -> rotate(bitmap, 270.toFloat())

            else -> bitmap
        }
    }

imagePath 的值为

imagePath = "/storage/emulated/0/DCIM/Camera/IMG_20200319_211738.jpg"

但是我在 ExifInterface(File(imagePath).absolutePath) 行中遇到了一个异常..!

Method threw 'java.io.FileNotFoundException' exception.
android.system.ErrnoException: open failed: EACCES (Permission denied)

我究竟做错了什么..?

4

0 回答 0