调整屏幕适配

main
liuguijing 8 months ago
parent d82d8a7540
commit 30c01a5068

@ -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) {
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 scale = Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
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);

Loading…
Cancel
Save