mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-04-04 02:31:09 +02:00
fixing some image rotation issues
This commit is contained in:
parent
715fc4f79a
commit
f73cb32db8
@ -1,11 +1,13 @@
|
|||||||
package com.simplemobiletools.camera.helpers
|
package com.simplemobiletools.camera.helpers
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.Matrix
|
import android.graphics.Matrix
|
||||||
import android.media.ExifInterface
|
import android.media.ExifInterface
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import com.simplemobiletools.camera.R
|
import com.simplemobiletools.camera.R
|
||||||
import com.simplemobiletools.camera.activities.MainActivity
|
import com.simplemobiletools.camera.activities.MainActivity
|
||||||
@ -22,6 +24,7 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
|
|||||||
val isThirdPartyIntent: Boolean) :
|
val isThirdPartyIntent: Boolean) :
|
||||||
AsyncTask<ByteArray, Void, String>() {
|
AsyncTask<ByteArray, Void, String>() {
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
override fun doInBackground(vararg params: ByteArray): String {
|
override fun doInBackground(vararg params: ByteArray): String {
|
||||||
var fos: OutputStream? = null
|
var fos: OutputStream? = null
|
||||||
val path: String
|
val path: String
|
||||||
@ -92,11 +95,8 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
|
|||||||
|
|
||||||
if (isUsingFrontCamera && activity.config.flipPhotos) {
|
if (isUsingFrontCamera && activity.config.flipPhotos) {
|
||||||
val matrix = Matrix()
|
val matrix = Matrix()
|
||||||
if (path.startsWith(activity.internalStoragePath)) {
|
val isPortrait = image.width < image.height
|
||||||
matrix.preScale(1f, -1f)
|
matrix.preScale(if (isPortrait) -1f else 1f, if (isPortrait) 1f else -1f)
|
||||||
} else {
|
|
||||||
matrix.preScale(-1f, 1f)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false)
|
image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false)
|
||||||
@ -116,12 +116,27 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (activity.config.savePhotoMetadata && !isThirdPartyIntent) {
|
if (activity.config.savePhotoMetadata && !isThirdPartyIntent) {
|
||||||
val fileExif = ExifInterface(path)
|
val exifInterface = if (path.startsWith(activity.internalStoragePath) || !isNougatPlus()) {
|
||||||
tempExif.copyTo(fileExif)
|
ExifInterface(path)
|
||||||
|
} else {
|
||||||
|
val documentFile = activity.getSomeDocumentFile(path)
|
||||||
|
if (documentFile != null) {
|
||||||
|
val parcelFileDescriptor = activity.contentResolver.openFileDescriptor(documentFile.uri, "rw")
|
||||||
|
val fileDescriptor = parcelFileDescriptor.fileDescriptor
|
||||||
|
ExifInterface(fileDescriptor)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exifInterface != null) {
|
||||||
|
tempExif.copyTo(exifInterface)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return photoFile.absolutePath
|
return photoFile.absolutePath
|
||||||
} catch (e: FileNotFoundException) {
|
} catch (e: FileNotFoundException) {
|
||||||
|
activity.showErrorToast(e)
|
||||||
} finally {
|
} finally {
|
||||||
fos?.close()
|
fos?.close()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user