From c7f55292d60327dc08046869598ba1b1ee1abdf7 Mon Sep 17 00:00:00 2001 From: Ismael Moreira Date: Wed, 20 Nov 2024 11:28:01 -0300 Subject: [PATCH] feat: Adjust Preview resolution to comply with `photo` if `video` is disabled (#3295) * docs: Update preview documentation and improve CameraSession configuration logic * refactor: put back the style * Update package/android/src/main/java/com/mrousavy/camera/core/CameraSession+Configuration.kt * put back the code style * Update docs/docs/guides/PREVIEW.mdx --------- Co-authored-by: Marc Rousavy --- docs/docs/guides/PREVIEW.mdx | 13 +++++++++++-- .../camera/core/CameraSession+Configuration.kt | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/docs/guides/PREVIEW.mdx b/docs/docs/guides/PREVIEW.mdx index eafad79bad..1ce2a5415f 100644 --- a/docs/docs/guides/PREVIEW.mdx +++ b/docs/docs/guides/PREVIEW.mdx @@ -62,7 +62,16 @@ const lowResolutionFormat = useCameraFormat(device, [ ]) ``` -On Android, the Preview will always be in full HD, or the Preview View's size, whichever is smaller. +On Android, the Preview will always be in full HD or the Preview View's size, whichever is smaller. +If a format is specified, the preview will try to match the `video`'s resolution and aspect ratio if `video` is enabled, and `photo`'s resolution and aspect ratio if `photo` is enabled. + +```tsx + +``` ### Overlays and Masks @@ -77,4 +86,4 @@ On Android, the Preview View supports two implementation modes which are control
-#### 🚀 Next section: [Taking Photos](./taking-photos) +#### 🚀 Next section: [Taking Photos](./taking-photos) \ No newline at end of file diff --git a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession+Configuration.kt b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession+Configuration.kt index 7c5cf05ae2..1e9c0def64 100644 --- a/package/android/src/main/java/com/mrousavy/camera/core/CameraSession+Configuration.kt +++ b/package/android/src/main/java/com/mrousavy/camera/core/CameraSession+Configuration.kt @@ -75,9 +75,11 @@ internal fun CameraSession.configureOutputs(configuration: CameraConfiguration) } if (format != null) { - // Similar to iOS, Preview will follow video size as it's size (and aspect ratio) + // Preview will follow video size as it's size & aspect ratio, or photo- if video is disabled. + val targetSize = if (videoConfig != null) format.videoSize else format.photoSize + val previewResolutionSelector = ResolutionSelector.Builder() - .forSize(format.videoSize) + .forSize(targetSize) .setAllowedResolutionMode(ResolutionSelector.PREFER_CAPTURE_RATE_OVER_HIGHER_RESOLUTION) .build() preview.setResolutionSelector(previewResolutionSelector)