androidx.camera.viewfinder.compose

Standalone Composable Viewfinder for Camera

Interfaces

CoordinateTransformer

Coordinate transformer that's used to convert coordinates from one space to another.

MutableCoordinateTransformer

CoordinateTransformer where the transformMatrix is mutable.

ViewfinderInitScope

A scoped environment provided when a Viewfinder is first initialized.

Objects

IdentityCoordinateTransformer

CoordinateTransformer where the transformMatrix is the identity matrix.

Top-level functions summary

MutableCoordinateTransformer

Creates a MutableCoordinateTransformer with the given matrix as the transformMatrix.

Unit
@Composable
Viewfinder(
    surfaceRequest: ViewfinderSurfaceRequest,
    modifier: Modifier,
    transformationInfo: TransformationInfo,
    coordinateTransformer: MutableCoordinateTransformer?,
    alignment: Alignment,
    contentScale: ContentScale,
    onInit: ViewfinderInitScope.() -> Unit
)

Displays a media stream with the given transformations for crop and rotation while maintaining proper scaling.

Top-level functions

MutableCoordinateTransformer

fun MutableCoordinateTransformer(matrix: Matrix = Matrix()): MutableCoordinateTransformer

Creates a MutableCoordinateTransformer with the given matrix as the transformMatrix.

@Composable
fun Viewfinder(
    surfaceRequest: ViewfinderSurfaceRequest,
    modifier: Modifier = Modifier,
    transformationInfo: TransformationInfo = DEFAULT,
    coordinateTransformer: MutableCoordinateTransformer? = null,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Crop,
    onInit: ViewfinderInitScope.() -> Unit
): Unit

Displays a media stream with the given transformations for crop and rotation while maintaining proper scaling.

A Surface for the given ViewfinderSurfaceRequest can be retrieved from the ViewfinderSurfaceSessionScope of the callback registered via ViewfinderInitScope.onSurfaceSession in onInit.

This has two underlying implementations either using an AndroidEmbeddedExternalSurface for ImplementationMode.EMBEDDED or an AndroidExternalSurface for ImplementationMode.EXTERNAL. These can be set by the ImplementationMode argument in the surfaceRequest constructor. If the implementation mode is null, then ImplementationMode.EXTERNAL will be used.

The onInit lambda, and the callback registered with ViewfinderInitScope.onSurfaceSession, are always called from the main thread. onInit will be called every time a new surfaceRequest is provided.

Parameters
surfaceRequest: ViewfinderSurfaceRequest

Details about the surface being requested

modifier: Modifier = Modifier

Modifier to be applied to the Viewfinder

transformationInfo: TransformationInfo = DEFAULT

Specifies the required transformations for the media being displayed.

coordinateTransformer: MutableCoordinateTransformer? = null

Coordinate transformer that can be used to convert Compose space coordinates such as touch coordinates to surface space coordinates. When the Viewfinder is displaying content from the camera, this transformer can be used to translate touch events into camera sensor coordinates for focus and metering actions.

alignment: Alignment = Alignment.Center

Optional alignment parameter used to place the Surface in the given bounds of the Viewfinder. Defaults to Alignment.Center.

contentScale: ContentScale = ContentScale.Crop

Optional scale parameter used to determine the aspect ratio scaling to be used to fit the Surface in the bounds of the Viewfinder. Defaults to ContentScale.Crop.

onInit: ViewfinderInitScope.() -> Unit

Lambda invoked on first composition and any time a new surfaceRequest is provided. This lambda can be used to declare a ViewfinderInitScope.onSurfaceSession callback that will be called each time a new Surface is provided by the viewfinder.

TODO(b/322420487): Add a sample with @sample