Skip to content

Commit

Permalink
feat: Adjust Preview resolution to comply with photo if video is …
Browse files Browse the repository at this point in the history
…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 <marcrousavy@hotmail.com>
  • Loading branch information
ismaelsousa and mrousavy authored Nov 20, 2024
1 parent 16d97d0 commit c7f5529
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 11 additions & 2 deletions docs/docs/guides/PREVIEW.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
<Camera
{...props}
format={bestFormatForPhoto}
photo={true} // Preview will be in the photo resolution
/>
```

### Overlays and Masks

Expand All @@ -77,4 +86,4 @@ On Android, the Preview View supports two implementation modes which are control

<br />

#### 🚀 Next section: [Taking Photos](./taking-photos)
#### 🚀 Next section: [Taking Photos](./taking-photos)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c7f5529

Please sign in to comment.