diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/overlay/OverlayLayout.java b/cameraview/src/main/java/com/otaliastudios/cameraview/overlay/OverlayLayout.java index 3327fde9..eff94def 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/overlay/OverlayLayout.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/overlay/OverlayLayout.java @@ -106,8 +106,10 @@ public class OverlayLayout extends FrameLayout implements Overlay { case VIDEO_SNAPSHOT: case PICTURE_SNAPSHOT: canvas.save(); - // The input canvas has the Surface dimensions which means it is guaranteed - // to have our own aspect ratio. But we might still have to apply some scale. + // The input canvas size is that of the preview stream, cropped to match + // the view aspect ratio (this op is done by picture & video recorder). + // So the aspect ratio is guaranteed to be the same, but we might have + // to apply some scale (typically > 1). float widthScale = canvas.getWidth() / (float) getWidth(); float heightScale = canvas.getHeight() / (float) getHeight(); LOG.i("draw", diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/picture/SnapshotGlPictureRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/picture/SnapshotGlPictureRecorder.java index 53c1fa9b..cbe3512b 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/picture/SnapshotGlPictureRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/picture/SnapshotGlPictureRecorder.java @@ -177,14 +177,10 @@ public class SnapshotGlPictureRecorder extends PictureRecorder { mOverlaySurfaceTexture.getTransformMatrix(mOverlayTransform); // 2. Then we can apply the transformations. - // TODO check the sign of this angle. - int rotation = mEngine.getAngles().offset(Reference.VIEW, Reference.OUTPUT, Axis.RELATIVE_TO_SENSOR); + int rotation = mEngine.getAngles().offset(Reference.VIEW, Reference.OUTPUT, Axis.ABSOLUTE); Matrix.translateM(mOverlayTransform, 0, 0.5F, 0.5F, 0); - Matrix.rotateM(mOverlayTransform, 0, -rotation, 0, 0, 1); - // Not sure why we have to flip the y axis (twice?). - if (mResult.facing == Facing.FRONT) { - Matrix.scaleM(mOverlayTransform, 0, -1, -1, 1); - } + Matrix.rotateM(mOverlayTransform, 0, rotation, 0, 0, 1); + // No need to flip the x axis for front camera, but need to flip the y axis always. Matrix.scaleM(mOverlayTransform, 0, 1, -1, 1); Matrix.translateM(mOverlayTransform, 0, -0.5F, -0.5F, 0); } diff --git a/demo/src/main/res/layout/activity_camera.xml b/demo/src/main/res/layout/activity_camera.xml index cd4773d9..c080b4aa 100644 --- a/demo/src/main/res/layout/activity_camera.xml +++ b/demo/src/main/res/layout/activity_camera.xml @@ -48,10 +48,9 @@ android:layout_height="wrap_content" android:src="@mipmap/cameraview" />