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
Landry Norris
07/28/2021, 5:45 PM
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
Zach Klippenstein (he/him) [MOD]
07/28/2021, 5:45 PM
You could probably just use a
ComposeView
directly to do that, don’t need another container view