I have an understanding problem. I take a photo and then want to display it in the correct orientation. If I run through the whole thing on the emulator, everything works. Only on the right device, the picture in portrait mode is always displayed rotated to the horizontal and saved in the gallery.
val rotatedBitmap = getPictureBitmap(path,capturedImg!!)
private fun getPictureBitmap(yourPathToPicture: String?, bitmap:Bitmap): Bitmap? {
val ei: ExifInterface = ExifInterface(yourPathToPicture!!)
val orientation = ei.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED
)
var rotatedBitmap: Bitmap? = null
when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> rotatedBitmap = rotateImage(bitmap, 90)
ExifInterface.ORIENTATION_ROTATE_180 -> rotatedBitmap = rotateImage(bitmap, 180)
ExifInterface.ORIENTATION_ROTATE_270 -> rotatedBitmap = rotateImage(bitmap, 270)
ExifInterface.ORIENTATION_NORMAL -> rotatedBitmap = bitmap
else -> rotatedBitmap = bitmap
}
return rotatedBitmap
}
...
val rotatedBitmap = getPictureBitmap(path,capturedImg!!)
//Correct format in the emulator. It will also be saved to the gallery in the correct format. But not on the real device
MediaStore.Images.Media.insertImage(contentResolver, rotatedBitmap, null , null);