Function

draw

Jetpack Compose API reference for draw.

DrawScopeRetargetingSample

@Composable
fun DrawScopeRetargetingSample() {
    Box(
        modifier =
            Modifier.size(120.dp).drawWithCache {
                // Example that shows how to redirect rendering to an Android Picture and then
                // draw the picture into the original destination
                // Note:
                // Canvas#drawPicture is supported with hardware acceleration on Android API 23+
                // Check
                // https://developer.android.com/topic/performance/hardware-accel#drawing-support
                // for details of which drawing operations are supported with hardware acceleration
                val picture = android.graphics.Picture()
                val width = this.size.width.toInt()
                val height = this.size.height.toInt()
                onDrawWithContent {
                    val pictureCanvas =
                        androidx.compose.ui.graphics.Canvas(picture.beginRecording(width, height))
                    draw(this, this.layoutDirection, pictureCanvas, this.size) {
                        [email protected]()
                    }
                    picture.endRecording()
                    drawIntoCanvas { canvas -> canvas.nativeCanvas.drawPicture(picture) }
                }
            }
    )
}