Android EXIF方向始终返回1
我正在尝试旋转从Android EXIF方向始终返回1,android,camera,orientation,exif,Android,Camera,Orientation,Exif,我正在尝试旋转从动作图像捕获获取的图像,以始终在横向模式下显示。我面临的问题是,EXIF-Orientation始终为1,与我拍照的方向无关 代码如下: 我在哪里拍照 我尝试检查图像方向的地方 值orientation始终为1。我做错了什么或错过了什么 private fun takePhoto(option: Int) { val storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES) val photo
动作图像捕获
获取的图像,以始终在横向模式下显示。我面临的问题是,EXIF-Orientation
始终为1,与我拍照的方向无关
代码如下:
我在哪里拍照
我尝试检查图像方向的地方
值orientation
始终为1。我做错了什么或错过了什么
private fun takePhoto(option: Int)
{
val storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES)
val photoFile = File.createTempFile("ID_Card_", ".png", storageDir)
when(option)
{
SCAN_ID_CARD_FRONT -> front_id_card_path = photoFile.absolutePath
SCAN_ID_CARD_BACK -> back_id_card_path = photoFile.absolutePath
}
Intent(MediaStore.ACTION_IMAGE_CAPTURE).also { takePictureIntent ->
takePictureIntent.resolveActivity(packageManager)?.also {
photoFile.also {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile))
startActivityForResult(takePictureIntent, option)
}
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
{
when (requestCode)
{
SCAN_ID_CARD_FRONT ->
{
if (resultCode == Activity.RESULT_OK)
{
val imageBitmap = fixImageRotation(front_id_card_path)
id_card_front.setImageBitmap(imageBitmap)
}
}
}
}
private fun fixImageRotation(file: String): Bitmap
{
val imageFile = File(file)
val exif = ExifInterface(imageFile.absolutePath)
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
val imageBitmap = BitmapFactory.decodeFile(file)
return when (orientation)
{
ExifInterface.ORIENTATION_NORMAL -> rotateImage(imageBitmap, -90)
ExifInterface.ORIENTATION_ROTATE_90 -> rotateImage(imageBitmap, 90)
ExifInterface.ORIENTATION_ROTATE_180 -> rotateImage(imageBitmap, 180)
ExifInterface.ORIENTATION_ROTATE_270 -> rotateImage(imageBitmap, 270)
else -> imageBitmap
}
}