Comply with EXIF settings when editing a picture

This commit is contained in:
Frédéric Gerber 2021-09-17 16:45:47 +02:00
parent 002b1548e1
commit 6eaae47140
2 changed files with 25 additions and 8 deletions

View File

@ -1,6 +1,8 @@
package org.pixeldroid.app.postCreation.photoEdit
import android.graphics.Bitmap
import android.graphics.ImageDecoder
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import android.util.TypedValue
@ -54,17 +56,19 @@ class FilterListFragment : Fragment() {
private fun displayImage(bitmap: Bitmap?) {
val r = Runnable {
val tbImage: Bitmap = (if (bitmap == null) {
// TODO: Shouldn't use deprecated API on newer versions of Android,
// but the proper way to do it seems to crash for OpenGL reasons
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// ImageDecoder.decodeBitmap(
// ImageDecoder.createSource(requireActivity().contentResolver, PhotoEditActivity.imageUri!!))
//} else {
// TODO: Check that there is no crash for OpenGL reasons on newer versions of Android
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// Honor EXIF orientation if API >= 28
ImageDecoder.decodeBitmap(ImageDecoder
.createSource(requireActivity().contentResolver, PhotoEditActivity.imageUri!!))
.copy(Bitmap.Config.ARGB_8888,true)
} else {
// Ignore EXIF orientation otherwise
MediaStore.Images.Media.getBitmap(
requireActivity().contentResolver,
PhotoEditActivity.imageUri
)
//}
}
} else {
Bitmap.createScaledBitmap(bitmap, 100, 100, false)
})

View File

@ -5,9 +5,12 @@ import android.app.AlertDialog
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.ImageDecoder
import android.graphics.Point
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.MediaStore
import android.view.Menu
@ -116,7 +119,17 @@ class PhotoEditActivity : BaseActivity() {
private fun loadImage() {
originalImage = MediaStore.Images.Media.getBitmap(contentResolver, imageUri)
// TODO: Check that there is no crash for OpenGL reasons on newer versions of Android
originalImage = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// Honor EXIF orientation if API >= 28
ImageDecoder
.decodeBitmap(ImageDecoder.createSource(contentResolver, imageUri!!))
.copy(BITMAP_CONFIG,true)
} else {
// Ignore EXIF orientation otherwise
MediaStore.Images.Media.getBitmap(contentResolver, imageUri)
}
compressedImage = resizeImage(originalImage!!)
compressedOriginalImage = compressedImage!!.copy(BITMAP_CONFIG, true)
filteredImage = compressedImage!!.copy(BITMAP_CONFIG, true)