Screenshot a composable
The print-compose module allows you to capture a Composable as an
image (ImageBitmap)
1. Creating the state
val screenshotState = rememberScreenshotState()
2. Registering the Composable to be captured
Wrap the desired content inside ScreenshotArea:
ScreenshotArea(
screenshotState = screenshotState
) {
Box(
Modifier
.size(200.dp)
.background(Color.Red)
)
}
The content inside ScreenshotArea is what will be converted into a androidx.compose.ui.graphics.ImageBitmap
3. Capturing the image
Use:
val bitmap = screenshotState.takeScreenshot()
bitmap will be an instance of ImageBitmap representing the content when screenshotState.takeScreenshot() was called.