make sure we rotate the final photo properly

This commit is contained in:
tibbi 2017-04-07 21:35:23 +02:00
parent b45b4cf4a3
commit 26f0a46ce9
2 changed files with 6 additions and 4 deletions

View File

@ -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<ByteArray, Void, String>() {
class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId: Int, val deviceOrientation: Int) : AsyncTask<ByteArray, Void, String>() {
companion object {
private val TAG = PhotoProcessor::class.java.simpleName
private var mActivity: WeakReference<MainActivity>? = 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)
}

View File

@ -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() {