Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 637
JustSightseeing Avatar asked Aug 31 '25 15:08

JustSightseeing


2 Answers

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.

like image 124
Chris Avatar answered Sep 02 '25 11:09

Chris


Coil is capable of displaying a Bitmap inside Image:

Image(
    painter = rememberAsyncImagePainter(imageBitmap),
    contentDescription = null,
)
like image 42
Philip Dukhov Avatar answered Sep 02 '25 09:09

Philip Dukhov