properly rotate the image in selfie mode

This commit is contained in:
tibbi 2018-06-04 22:10:35 +02:00
parent 7e0b355438
commit c75f1cabfa
1 changed files with 10 additions and 6 deletions

View File

@ -199,12 +199,16 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
val buffer = reader.acquireNextImage().planes[0].buffer val buffer = reader.acquireNextImage().planes[0].buffer
val bytes = ByteArray(buffer.remaining()) val bytes = ByteArray(buffer.remaining())
buffer.get(bytes) buffer.get(bytes)
PhotoProcessor(mActivity, mTargetUri, mRotationAtCapture, mSensorOrientation, getIsUsingFrontCamera()).execute(bytes) PhotoProcessor(mActivity, mTargetUri, mRotationAtCapture, getJPEGOrientation(), mUseFrontCamera).execute(bytes)
} }
private fun getIsUsingFrontCamera(): Boolean { private fun getJPEGOrientation(): Int {
val facing = getCameraCharacteristics().get(CameraCharacteristics.LENS_FACING) var orientation = mSensorOrientation
return facing == CameraCharacteristics.LENS_FACING_FRONT if (mUseFrontCamera) {
orientation += 180
}
return orientation % 360
} }
private fun setupCameraOutputs(width: Int, height: Int) { private fun setupCameraOutputs(width: Int, height: Int) {
@ -403,7 +407,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
addTarget(mImageReader!!.surface) addTarget(mImageReader!!.surface)
setFlashAndExposure(this) setFlashAndExposure(this)
set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE) set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
set(CaptureRequest.JPEG_ORIENTATION, mSensorOrientation) set(CaptureRequest.JPEG_ORIENTATION, getJPEGOrientation())
set(CaptureRequest.SCALER_CROP_REGION, mZoomRect) set(CaptureRequest.SCALER_CROP_REGION, mZoomRect)
set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE) set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE)
} }
@ -525,7 +529,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
} }
private fun calculateCameraToPreviewMatrix() { private fun calculateCameraToPreviewMatrix() {
val yScale = if (getIsUsingFrontCamera()) -1 else 1 val yScale = if (mUseFrontCamera) -1 else 1
mCameraToPreviewMatrix.apply { mCameraToPreviewMatrix.apply {
reset() reset()
setScale(1f, yScale.toFloat()) setScale(1f, yScale.toFloat())