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 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",

@ -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);
}

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

Loading…
Cancel
Save