Skip to content

Instantly share code, notes, and snippets.

@ch8n
Created October 16, 2021 11:22
Show Gist options
  • Save ch8n/a02f4079a9e4cd1dbc3cc48e4f60d68c to your computer and use it in GitHub Desktop.
Save ch8n/a02f4079a9e4cd1dbc3cc48e4f60d68c to your computer and use it in GitHub Desktop.
@Composable
fun CaptureBitmap(
content: @Composable ()->Unit
) : () -> Bitmap // <---- this will return a callback which returns a bitmap
{
val composeView = ComposeView(...)
//callback that convert view to bitmap
fun captureBitmap() = composeView.drawToBitmap()
AndroidView(
factory = {
composeView.apply {
setContent {
content.invoke() // <--- Content get places in between this code
}
}
}
)
return ::captureBitmap // <--- return functional reference of the callback
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment