Fix picture snapshots

pull/502/head
Mattia Iavarone 6 years ago
parent e4a63339aa
commit e057f9d238
  1. 6
      cameraview/src/main/java/com/otaliastudios/cameraview/overlay/OverlayLayout.java
  2. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/picture/SnapshotGlPictureRecorder.java
  3. 3
      demo/src/main/res/layout/activity_camera.xml

@ -106,8 +106,10 @@ public class OverlayLayout extends FrameLayout implements Overlay {
case VIDEO_SNAPSHOT: case VIDEO_SNAPSHOT:
case PICTURE_SNAPSHOT: case PICTURE_SNAPSHOT:
canvas.save(); canvas.save();
// The input canvas has the Surface dimensions which means it is guaranteed // The input canvas size is that of the preview stream, cropped to match
// to have our own aspect ratio. But we might still have to apply some scale. // 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 widthScale = canvas.getWidth() / (float) getWidth();
float heightScale = canvas.getHeight() / (float) getHeight(); float heightScale = canvas.getHeight() / (float) getHeight();
LOG.i("draw", LOG.i("draw",

@ -177,14 +177,10 @@ public class SnapshotGlPictureRecorder extends PictureRecorder {
mOverlaySurfaceTexture.getTransformMatrix(mOverlayTransform); mOverlaySurfaceTexture.getTransformMatrix(mOverlayTransform);
// 2. Then we can apply the transformations. // 2. Then we can apply the transformations.
// TODO check the sign of this angle. int rotation = mEngine.getAngles().offset(Reference.VIEW, Reference.OUTPUT, Axis.ABSOLUTE);
int rotation = mEngine.getAngles().offset(Reference.VIEW, Reference.OUTPUT, Axis.RELATIVE_TO_SENSOR);
Matrix.translateM(mOverlayTransform, 0, 0.5F, 0.5F, 0); Matrix.translateM(mOverlayTransform, 0, 0.5F, 0.5F, 0);
Matrix.rotateM(mOverlayTransform, 0, -rotation, 0, 0, 1); Matrix.rotateM(mOverlayTransform, 0, rotation, 0, 0, 1);
// Not sure why we have to flip the y axis (twice?). // No need to flip the x axis for front camera, but need to flip the y axis always.
if (mResult.facing == Facing.FRONT) {
Matrix.scaleM(mOverlayTransform, 0, -1, -1, 1);
}
Matrix.scaleM(mOverlayTransform, 0, 1, -1, 1); Matrix.scaleM(mOverlayTransform, 0, 1, -1, 1);
Matrix.translateM(mOverlayTransform, 0, -0.5F, -0.5F, 0); Matrix.translateM(mOverlayTransform, 0, -0.5F, -0.5F, 0);
} }

@ -48,10 +48,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@mipmap/cameraview" /> android:src="@mipmap/cameraview" />
<TextView <TextView
android:id="@+id/watermark_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="CameraView" android:text="Watermark"
android:textColor="@android:color/white" /> android:textColor="@android:color/white" />
</LinearLayout> </LinearLayout>

Loading…
Cancel
Save