icerockdev / moko-media

Media selection & presenting for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
120 stars 12 forks source link

fix rotation for specific devices #26

Closed denmusic1992 closed 3 years ago

denmusic1992 commented 3 years ago

There is a problem with a photo rotation. The method for picking images returns an image rotated 90 degrees. When i use this code:

val image: Bitmap = mediaController.pickImage(mediaSource)

it doesn't work as I expect for some devices, like LG X Power / Android 6.0.1 / 5,3 display Nexus one / Android 7.0 / 3.4 480x800 hdpi

The expected behavior is when the returned image is rotated properly.

Alex009 commented 3 years ago

first - we should update exifinterface library - https://developer.android.com/jetpack/androidx/releases/exifinterface#version_132_3 second - we should always use content resolver logic for read photos. and in all cases it should be same logic. now we have separated parts:

https://github.com/icerockdev/moko-media/blob/5b4013cc239e4a6d8608168a693d159b043b1221/media/src/androidMain/kotlin/dev/icerock/moko/media/MediaFactory.kt#L73 here we read content resolver, rotate photo. BUT here should be also logic for sampling (if we pass limits of sizes)

https://github.com/icerockdev/moko-media/blob/5b4013cc239e4a6d8608168a693d159b043b1221/media/src/androidMain/kotlin/dev/icerock/moko/media/picker/MediaPickerController.kt#L253 here we read content resolver, apply sampling logic, BUT not rotate photo by exif interface.

https://github.com/icerockdev/moko-media/blob/5b4013cc239e4a6d8608168a693d159b043b1221/media/src/androidMain/kotlin/dev/icerock/moko/media/picker/MediaPickerController.kt#L292 here we read content resolver, read angle, BUT not apply sampling. also here read angle from file, not content resolver. https://github.com/icerockdev/moko-media/blob/5b4013cc239e4a6d8608168a693d159b043b1221/media/src/androidMain/kotlin/dev/icerock/moko/media/BitmapUtils.kt#L17

also orientations reading here https://github.com/icerockdev/moko-media/blob/5b4013cc239e4a6d8608168a693d159b043b1221/media/src/androidMain/kotlin/dev/icerock/moko/media/BitmapUtils.kt#L22 contains not all cases

we should process any photo by one logic, not separated duplicated parts