Fix preview sizing bug

pull/99/head
Mattia Iavarone 8 years ago
parent 6c26a3aa85
commit 71c2feb703
  1. 1
      README.md
  2. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java

@ -707,7 +707,6 @@ all the code was changed.
These are still things that need to be done, off the top of my head: These are still things that need to be done, off the top of my head:
- [ ] `Camera2` integration - [ ] `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 - [ ] animate grid lines similar to stock camera app
- [ ] add onRequestPermissionResults for easy permission callback - [ ] add onRequestPermissionResults for easy permission callback
- [ ] decent code coverage - [ ] decent code coverage

@ -425,8 +425,12 @@ abstract class CameraController implements
} }
protected Size computePreviewSize(List<Size> previewSizes) { protected Size computePreviewSize(List<Size> 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()); AspectRatio targetRatio = AspectRatio.of(mPictureSize.getWidth(), mPictureSize.getHeight());
Size targetMinSize = mPreview.getSurfaceSize(); Size targetMinSize = mPreview.getSurfaceSize();
if (flip) targetMinSize.flip();
LOG.i("size:", "computePreviewSize:", "targetRatio:", targetRatio, "targetMinSize:", targetMinSize); LOG.i("size:", "computePreviewSize:", "targetRatio:", targetRatio, "targetMinSize:", targetMinSize);
SizeSelector matchRatio = SizeSelectors.aspectRatio(targetRatio, 0); SizeSelector matchRatio = SizeSelectors.aspectRatio(targetRatio, 0);
SizeSelector matchSize = SizeSelectors.and( SizeSelector matchSize = SizeSelectors.and(
@ -437,7 +441,11 @@ abstract class CameraController implements
matchRatio, // If couldn't match both, match ratio. matchRatio, // If couldn't match both, match ratio.
SizeSelectors.biggest() // If couldn't match any, take the biggest. 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 @NonNull

Loading…
Cancel
Save