From 48eb56098323928aee39e7285cc8a801350d9db8 Mon Sep 17 00:00:00 2001 From: Andrewerr Date: Sat, 18 Nov 2023 20:54:28 +0100 Subject: [PATCH] Mirror image when freezing --- app/src/main/java/com/polar/mirror/FreezeController.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/polar/mirror/FreezeController.java b/app/src/main/java/com/polar/mirror/FreezeController.java index 2dd62d9..674e3a1 100644 --- a/app/src/main/java/com/polar/mirror/FreezeController.java +++ b/app/src/main/java/com/polar/mirror/FreezeController.java @@ -53,7 +53,7 @@ public class FreezeController { * @param provider camera provider * @param lcOwner lifecycle owner used for binding camera usecases */ - public void onCameraInitialized(ProcessCameraProvider provider, LifecycleOwner lcOwner){ + public void onCameraInitialized(@NonNull ProcessCameraProvider provider, LifecycleOwner lcOwner){ CameraSelector cameraSelector = new CameraSelector.Builder() .requireLensFacing(CameraSelector.LENS_FACING_FRONT) .build(); @@ -82,11 +82,18 @@ private int getRotationAngleFromOrientation(int orientation){ private Bitmap processFreezeImage(byte[] bytes){ Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); Matrix matrix = new Matrix(); + // Rotate image int rotation = getRotationAngleFromOrientation(Utils.getOrientation(mContext)); matrix.postRotate(rotation); bitmap = Bitmap.createBitmap( bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true ); + //Mirror image + matrix = new Matrix(); + matrix.preScale(-1.0f, 1.0f); + bitmap = Bitmap.createBitmap( + bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true + ); return bitmap; }