diff --git a/README.md b/README.md index 677ba962..88f324b2 100644 --- a/README.md +++ b/README.md @@ -707,7 +707,6 @@ all the code was changed. These are still things that need to be done, off the top of my head: - [ ] `Camera2` integration -- [ ] add a `setPreferredAspectRatio` API to choose the capture size. Preview size will adapt, and then, if let free, the CameraView will adapt as well - [ ] animate grid lines similar to stock camera app - [ ] add onRequestPermissionResults for easy permission callback - [ ] decent code coverage diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java index 6dc9b8ef..2e2ba631 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java @@ -425,8 +425,12 @@ abstract class CameraController implements } protected Size computePreviewSize(List previewSizes) { + // instead of flipping everything to the view world, we can just flip the + // surface size to the sensor world + boolean flip = shouldFlipSizes(); AspectRatio targetRatio = AspectRatio.of(mPictureSize.getWidth(), mPictureSize.getHeight()); Size targetMinSize = mPreview.getSurfaceSize(); + if (flip) targetMinSize.flip(); LOG.i("size:", "computePreviewSize:", "targetRatio:", targetRatio, "targetMinSize:", targetMinSize); SizeSelector matchRatio = SizeSelectors.aspectRatio(targetRatio, 0); SizeSelector matchSize = SizeSelectors.and( @@ -437,7 +441,11 @@ abstract class CameraController implements matchRatio, // If couldn't match both, match ratio. SizeSelectors.biggest() // If couldn't match any, take the biggest. ); - return matchAll.select(previewSizes).get(0); + Size result = matchAll.select(previewSizes).get(0); + LOG.i("computePreviewSize:", "result:", result); + // Flip back what we flipped. + if (flip) targetMinSize.flip(); + return result; } @NonNull