ExifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,1)始终返回0

时间:2019-06-10 07:42:38

标签: android image kotlin exif

我正在尝试复制this answer来查找android图像的方向:

fun getCameraPhotoOrientation(context: Context, inputStream: InputStream, uri: Uri): Int {
    val exif = if (android.os.Build.VERSION.SDK_INT > 24) ExifInterface(inputStream) else ExifInterface(uri.path)
    val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1)
    val rotate = when (orientation){
        ExifInterface.ORIENTATION_ROTATE_270 -> 270
        ExifInterface.ORIENTATION_ROTATE_180 -> 180
        ExifInterface.ORIENTATION_ROTATE_90 -> 90
        else -> 0
    }
        Log.d(TAG, "Exif orientation: $orientation") // prints 0 every time
        Log.d(TAG, "Rotate value: $rotate") // prints 0 every time
    return rotate
}

即使我传递的图像以错误的方式上传(不是纵向),orientation仍返回0。

这是我调用的函数:

val inputStream = contentResolver.openInputStream(uri)!!
getCameraPhotoOrientation(this, inputStream, uri)

有什么解决方法吗?

0 个答案:

没有答案
相关问题