From 30c01a5068bd853908c06e04992fe6fbd1c19d65 Mon Sep 17 00:00:00 2001 From: liuguijing <123456> Date: Tue, 22 Oct 2024 16:18:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=B1=8F=E5=B9=95=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xypower/mppreview/Camera2RawFragment.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java b/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java index 55628d2..b669ab4 100644 --- a/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java +++ b/Application/src/main/java/com/xypower/mppreview/Camera2RawFragment.java @@ -1080,7 +1080,6 @@ public class Camera2RawFragment extends Fragment RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth()); float centerX = viewRect.centerX(); float centerY = viewRect.centerY(); - // Initially, output stream images from the Camera2 API will be rotated to the native // device orientation from the sensor's orientation, and the TextureView will default to // scaling these buffers to fill it's view bounds. If the aspect ratios and relative @@ -1098,13 +1097,27 @@ public class Camera2RawFragment extends Fragment // - Apply the rotation from the native device orientation to the current device // rotation. if (Surface.ROTATION_90 == deviceRotation || Surface.ROTATION_270 == deviceRotation) { - bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); - matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); - float scale = Math.max( - (float) viewHeight / previewSize.getHeight(), - (float) viewWidth / previewSize.getWidth()); - matrix.postScale(scale, scale, centerX, centerY); - + if (rotation == 0) { + matrix.postScale(1, 1); + } else if (rotation == 90){ + bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); + matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); + float scaleh = + (float) viewHeight / previewSize.getHeight(); + float scalew = + (float) viewWidth / previewSize.getWidth(); + matrix.postScale(scalew, scaleh, centerX, centerY); + } else if (rotation == 180){ + matrix.postScale(1, 1); + }else if (rotation == 270){ + bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); + matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); + float scaleh = + (float) viewHeight / previewSize.getHeight(); + float scalew = + (float) viewWidth / previewSize.getWidth(); + matrix.postScale(scaleh, scalew, centerX, centerY); + } } matrix.postRotate(rotation, centerX, centerY);