I would like to capture the UI emitted by Jetpack ...
# compose
a
I would like to capture the UI emitted by Jetpack compose as a Bitmap. In XML this was done like this: Basically takes a view as an input parameter and returns it as a Bitmap.
Copy code
//take screenshot of the view added as an input argument
fun takeScreenShot(view: View) : Bitmap {
    val bitmap = Bitmap.createBitmap(
        view.width,
        view.height,
        Bitmap.Config.ARGB_8888
    )
    val canvas = Canvas(bitmap)
    view.draw(canvas)
    return bitmap
}
What is the equivalent of this in Jetpack compose?
l
I don't think there's a great way to do this yet. From what I've seen, you can set up a View layout (such as ConstraintLayout, LinearLayout, etc) and call view.setContent { Composable() }, then use the old way of drawing the view.
z
You could probably just use a
ComposeView
directly to do that, don’t need another container view
m
FWIW, this approach was written up a couple of weeks ago: https://medium.com/@johannblake/create-bitmaps-from-jetpack-composables-bdb2c95db51