androidandroid-jetpack-composeandroid-bitmapandroid-image

How can I display a bitmap in Compose Image


I have a function that returns a bitmap (which "contains" a QR code) and I wanted to display that bitmap inside an Image (composable function) but I didn't find any way to either convert the bitmap into a ImageBitmap or just displaying that bitmap.


Solution

  • Based on this blog post, it should be possible to display a bitmap like this :

    @Composable
    fun BitmapImage(bitmap: Bitmap) {
        Image(
            bitmap = bitmap.asImageBitmap(),
            contentDescription = "some useful description",
        )
    }
    

    I haven't tried it out myself, but recently came across the blog post when looking into displaying maps using Jetpack Compose.