Skip to content

feat: Option to remove letterboxing in CameraPreview.start() #286

@caiosm1005

Description

@caiosm1005

Feature Request

Description

It'd be useful to have an option in CameraPreview.start() that removes letterboxing. This option would scale the image up so that no letterboxing is visible.

Image

Platform(s)

iOS, Android, Web

Preferred Solution

A new option aspectMode: 'cover' | 'contain' could be added to CameraPreviewOptions, defaulting to 'contain', which is the current behavior.

Setting it to 'cover' removes letterboxing. Please see suggested implementation under Additional Context.

Additional Context

iOS

The preview is an AVCaptureVideoPreviewLayer. To fill without bars you set:
videoGravity = .resizeAspectFill

(Instead of .resizeAspect, which produces letterboxing.)

Android

The preview is a TextureView/SurfaceView driven by CameraX/Camera2. You need the equivalent “scale to fill” behavior:

  • adjust the preview view's scale / transform matrix, or
  • use a PreviewView scale type that fills (when using CameraX PreviewView), or
  • compute a transform so the preview fills and crops.

Web

Simply add the following CSS to the <video> element when aspectMode is 'cover': object-fit: cover.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions