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 |
Objects
IdentityCoordinateTransformer |
|
Top-level functions summary
MutableCoordinateTransformer |
MutableCoordinateTransformer(matrix: Matrix)Creates a |
Unit |
@ComposableDisplays 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.
Viewfinder
@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 based on androidx.compose.foundation.AndroidEmbeddedExternalSurface for ImplementationMode.EMBEDDED or on androidx.compose.foundation.AndroidExternalSurface for ImplementationMode.EXTERNAL. These can be set by the ImplementationMode argument in the surfaceRequest constructor. If implementationMode is null, a default is chosen based on device compatibility. This default value, which can be retrieved from ViewfinderDefaults.implementationMode, will be ImplementationMode.EXTERNAL by default, switching to ImplementationMode.EMBEDDED on API levels 24 and below, or on devices with known compatibility issues with the EXTERNAL mode.
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, or if the ImplementationMode changes.
| Parameters | |
|---|---|
surfaceRequest: ViewfinderSurfaceRequest |
Details about the surface being requested |
modifier: Modifier = Modifier |
Modifier to be applied to the |
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 |
contentScale: ContentScale = ContentScale.Crop |
Optional scale parameter used to determine the aspect ratio scaling to be used to fit the |
onInit: ViewfinderInitScope.() -> Unit |
Lambda invoked on first composition and any time a new TODO(b/322420487): Add a sample with |