我目前正在尝试从像素手机中获取图像的方向,以使其正确旋转。调试Exif接口类后,观察到映像中没有TAG_ORIENTATION(这意味着没有exif数据)。通过MediaStore提取内容时,发现游标也没有返回任何列。
val exif = ExifInterface(inputStream!!)
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
val matrix = Matrix()
var rotation = 0f
when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> rotation = 90f
ExifInterface.ORIENTATION_ROTATE_180 -> rotation = 180f
ExifInterface.ORIENTATION_ROTATE_270 -> rotation = 270f
}
val bundle = Bundle()
bundle.putInt("exif_orientation", orientation)
firebaseAnalytics.logEvent("exif", bundle)
matrix.postRotate(rotation)
scaledBitmap = Bitmap.createBitmap(scaledBitmap!!, 0, 0, scaledBitmap.width, scaledBitmap.height, matrix, true)
Update
在为摄像头的应用添加权限后,我能够获取TAG_ORIENTATION。但是Android OS P和Q始终为零