Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[camera] Resolution #1837

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fix bug so that ResolutionPresets effect image capture size on Android.

## 0.5.2+1

* Fix bug that prevented video recording with audio.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ private class Camera {
isFrontFacing =
characteristics.get(CameraCharacteristics.LENS_FACING)
== CameraMetadata.LENS_FACING_FRONT;
computeBestCaptureSize(streamConfigurationMap);
computeBestPreviewAndRecordingSize(streamConfigurationMap, minHeight, captureSize);
computeBestSize(
streamConfigurationMap, minHeight, computeMaximumSize(streamConfigurationMap));

if (cameraPermissionContinuation != null) {
result.error("cameraPermission", "Camera permission request ongoing", null);
Expand Down Expand Up @@ -375,8 +375,8 @@ private boolean hasAudioPermission() {
== PackageManager.PERMISSION_GRANTED;
}

private void computeBestPreviewAndRecordingSize(
StreamConfigurationMap streamConfigurationMap, int minHeight, Size captureSize) {
private void computeBestSize(
StreamConfigurationMap streamConfigurationMap, int minHeight, Size maximumSize) {
Size[] sizes = streamConfigurationMap.getOutputSizes(SurfaceTexture.class);

// Preview size and video size should not be greater than screen resolution or 1080.
Expand Down Expand Up @@ -410,11 +410,11 @@ private void computeBestPreviewAndRecordingSize(
previewSize = sizes[0];
videoSize = sizes[0];
} else {
float captureSizeRatio = (float) captureSize.getWidth() / captureSize.getHeight();
float maximumSizeRatio = (float) maximumSize.getWidth() / maximumSize.getHeight();

previewSize = goodEnough.get(0);
for (Size s : goodEnough) {
if ((float) s.getWidth() / s.getHeight() == captureSizeRatio) {
if ((float) s.getWidth() / s.getHeight() == maximumSizeRatio) {
previewSize = s;
break;
}
Expand All @@ -423,20 +423,20 @@ private void computeBestPreviewAndRecordingSize(
Collections.reverse(goodEnough);
videoSize = goodEnough.get(0);
for (Size s : goodEnough) {
if ((float) s.getWidth() / s.getHeight() == captureSizeRatio) {
if ((float) s.getWidth() / s.getHeight() == maximumSizeRatio) {
videoSize = s;
break;
}
}
}
captureSize = previewSize;
}

private void computeBestCaptureSize(StreamConfigurationMap streamConfigurationMap) {
// For still image captures, we use the largest available size.
captureSize =
Collections.max(
Arrays.asList(streamConfigurationMap.getOutputSizes(ImageFormat.JPEG)),
new CompareSizesByArea());
private Size computeMaximumSize(StreamConfigurationMap streamConfigurationMap) {
// Determine the largest available size. We use for aspect ratio matching.
return Collections.max(
Arrays.asList(streamConfigurationMap.getOutputSizes(ImageFormat.JPEG)),
new CompareSizesByArea());
}

private void prepareMediaRecorder(String outputFilePath) throws IOException {
Expand Down