SkiaCameraRef

A reference to a SkiaCamera (the equivalent of a ref on V5's <SkiaCamera />, SkiaCameraRef). Create it with rememberSkiaCameraRef and pass it to SkiaCamera.

val camera = rememberSkiaCameraRef()
val scope = rememberCoroutineScope()
SkiaCamera(
device = TargetCameraPosition.BACK,
isActive = true,
ref = camera,
onFrame = { frame, render ->
render { (frameTexture, canvas) -> canvas.drawImage(frameTexture, 0f, 0f) }
frame.dispose()
},
modifier = Modifier.pointerInput(Unit) {
detectTapGestures { offset -> scope.launch { camera.focusTo(offset) } }
},
)
Button(onClick = {
val snapshot = camera.takeSnapshot()
println("Captured Skia snapshot! ${snapshot?.imageInfo}")
}) { Text("Snapshot") }

View coordinates are in Compose pixels, as in pointer events.

Properties

Link copied to clipboard

The graphics layer the SkiaCamera draws its rendered Frames into (V5's Skia Canvas ref), or null if it has not been laid out yet. It is set after the first composition, and usually won't change. For example, canvas?.toImageBitmap() captures what is currently displayed.

Link copied to clipboard

The current CameraController, or null if the Camera is not ready yet. It is set once the session is configured, and may change over time.

Functions

Link copied to clipboard

Converts the given viewPoint (in the SkiaCamera's coordinate system) to a normalized Point in the Camera's coordinate system, with values ranging from 0...1.

Link copied to clipboard
suspend fun focusTo(viewPoint: Offset, options: FocusOptions = FocusOptions())

Focuses the Camera pipeline to the specified viewPoint relative to the SkiaCamera's coordinate system, using the specified MeteringModes of the options.

Link copied to clipboard
suspend fun resetFocus()

Resets the focus, see CameraController.resetFocus.

Link copied to clipboard
fun takeSnapshot(): Image?

Takes a snapshot of the currently rendered content, or returns null if none is available. It must be called on the main thread. The caller owns the returned image, and closes it when done with it.