@@ -12,10 +12,7 @@ import com.simplemobiletools.camera.extensions.compensateDeviceRotation
1212import com.simplemobiletools.camera.extensions.config
1313import com.simplemobiletools.camera.extensions.getOutputMediaFile
1414import com.simplemobiletools.camera.extensions.getPreviewRotation
15- import com.simplemobiletools.commons.extensions.getFileDocument
16- import com.simplemobiletools.commons.extensions.needsStupidWritePermissions
17- import com.simplemobiletools.commons.extensions.showErrorToast
18- import com.simplemobiletools.commons.extensions.toast
15+ import com.simplemobiletools.commons.extensions.*
1916import java.io.File
2017import java.io.FileOutputStream
2118import java.io.OutputStream
@@ -67,9 +64,22 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
6764 else -> 0
6865 }
6966
70- image = rotate(image, (imageRot + deviceRot + previewRot) % 360 ) ? : return " "
71- image.compress(Bitmap .CompressFormat .JPEG , 80 , fos)
72- fos?.close()
67+ val totalRotation = (imageRot + deviceRot + previewRot) % 360
68+ val fileExif = ExifInterface (path)
69+ var exifOrientation = ExifInterface .ORIENTATION_NORMAL .toString()
70+ if (path.startsWith(activity.internalStoragePath)) {
71+ exifOrientation = getExifOrientation(totalRotation)
72+ } else {
73+ image = rotate(image, totalRotation)
74+ }
75+
76+ if (image != null ) {
77+ image.compress(Bitmap .CompressFormat .JPEG , 80 , fos)
78+ fos?.close()
79+ }
80+
81+ fileExif.setAttribute(ExifInterface .TAG_ORIENTATION , exifOrientation)
82+ fileExif.saveAttributes()
7383 return photoFile.absolutePath
7484 } catch (e: Exception ) {
7585 activity.showErrorToast(e)
@@ -80,6 +90,15 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
8090 return " "
8191 }
8292
93+ private fun getExifOrientation (degrees : Int ): String {
94+ return when (degrees) {
95+ 90 -> ExifInterface .ORIENTATION_ROTATE_90
96+ 180 -> ExifInterface .ORIENTATION_ROTATE_180
97+ 270 -> ExifInterface .ORIENTATION_ROTATE_270
98+ else -> ExifInterface .ORIENTATION_NORMAL
99+ }.toString()
100+ }
101+
83102 private fun rotate (bitmap : Bitmap , degree : Int ): Bitmap ? {
84103 if (degree == 0 )
85104 return bitmap
0 commit comments