Function

draw

DrawScopeRetargetingSample

@Sampled
@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) }
                }
            }
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: