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