fix #230, properly handle images captured with the front camera

This commit is contained in:
tibbi 2019-09-03 09:16:38 +02:00
parent b793026bbb
commit 715fc4f79a
3 changed files with 5 additions and 6 deletions

View File

@ -38,9 +38,8 @@ const val STATE_STARTING_RECORDING = 6
const val STATE_STOPING_RECORDING = 7
const val STATE_RECORDING = 8
fun compensateDeviceRotation(orientation: Int, isUsingFrontCamera: Boolean) = when {
orientation == ORIENT_LANDSCAPE_LEFT -> 270
orientation == ORIENT_LANDSCAPE_RIGHT -> 90
isUsingFrontCamera -> 180
fun compensateDeviceRotation(orientation: Int) = when (orientation) {
ORIENT_LANDSCAPE_LEFT -> 270
ORIENT_LANDSCAPE_RIGHT -> 90
else -> 0
}

View File

@ -79,7 +79,7 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
val imageRot = orient.degreesFromOrientation()
val deviceRot = compensateDeviceRotation(deviceOrientation, isUsingFrontCamera)
val deviceRot = compensateDeviceRotation(deviceOrientation)
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
val totalRotation = (imageRot + deviceRot + previewRotation) % 360

View File

@ -568,7 +568,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
mCameraState = STATE_PICTURE_TAKEN
mRotationAtCapture = mActivity.mLastHandledOrientation
val jpegOrientation = (mSensorOrientation + compensateDeviceRotation(mRotationAtCapture, mUseFrontCamera)) % 360
val jpegOrientation = (mSensorOrientation + compensateDeviceRotation(mRotationAtCapture)) % 360
val captureBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
addTarget(mImageReader!!.surface)
setFlashAndExposure(this)