Hey everyone! I am trying to create a ComposeView ...
# compose
s
Hey everyone! I am trying to create a ComposeView (with just context) and then turn it into a bitmap… The reason is to generate a map pin marker for google maps with compose. Currently I do the following (the preview annotation generates a good pin image, the size I expect it to be)
Copy code
val contentView = ComposeView(context = context).apply {
    setContent {
        ... composable ...
    }
    createComposition() // since no window is bound
}
val generator = IconGenerator(context).apply {
    setContentView(contentView)
}
val bitmap = generator.makeIcon()
If you debug the bitmap, you get a tiny (wrong size) drawing of the box’s shape, but not the entire rendered version of the shape. The generator is simple, and basically calls
Copy code
composeView.measure()
composeView.layout()
composeView.draw(canvas)
canvas.toBitmap()
Does anyone have ideas of what might cause compose view to skip rendering? Or where to look to more deeply understand how compose is working behind the scenes?