From 26f0a46ce96adb0db093bec7f05d123e7d5dff95 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 7 Apr 2017 21:35:23 +0200 Subject: [PATCH] make sure we rotate the final photo properly --- .../kotlin/com/simplemobiletools/camera/PhotoProcessor.kt | 6 +++--- app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt b/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt index 553224b5..b548f853 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/PhotoProcessor.kt @@ -22,7 +22,7 @@ import java.io.IOException import java.io.OutputStream import java.lang.ref.WeakReference -class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId: Int) : AsyncTask() { +class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId: Int, val deviceOrientation: Int) : AsyncTask() { companion object { private val TAG = PhotoProcessor::class.java.simpleName private var mActivity: WeakReference? = null @@ -66,7 +66,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId var image = BitmapFactory.decodeByteArray(data, 0, data.size) val exif = ExifInterface(photoFile.toString()) - val deviceRot = MainActivity.mLastHandledOrientation.compensateDeviceRotation(currCameraId) + val deviceRot = deviceOrientation.compensateDeviceRotation(currCameraId) val previewRot = activity.getPreviewRotation(currCameraId) val imageRot = when (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) { ExifInterface.ORIENTATION_ROTATE_90 -> 90 @@ -97,7 +97,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId val height = bitmap.height val matrix = Matrix() - matrix.setRotate(degree.toFloat()) + matrix.setRotate((degree % 360).toFloat()) return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true) } diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt index 62aa82a2..4831ed22 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt @@ -56,6 +56,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan private var mLastClickY = 0 private var mCurrCameraId = 0 private var mMaxZoom = 0 + private var mRotationAtCapture = 0 } constructor(context: Context) : super(context) @@ -273,6 +274,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan mCamera!!.enableShutterSound(false) } + mRotationAtCapture = MainActivity.mLastHandledOrientation mCamera!!.parameters = mParameters mCamera!!.takePicture(null, null, takePictureCallback) } @@ -288,7 +290,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan resumePreview() } - PhotoProcessor(mActivity, mTargetUri, mCurrCameraId).execute(data) + PhotoProcessor(mActivity, mTargetUri, mCurrCameraId, mRotationAtCapture).execute(data) } private fun resumePreview() {