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
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.
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
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.
Focuses the Camera pipeline to the specified viewPoint relative to the SkiaCamera's coordinate system, using the specified MeteringModes of the options.
Resets the focus, see CameraController.resetFocus.
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.