如何在 Compose Image 中显示位图

Jus*_*ing 26 android-image android-bitmap android-jetpack-compose

我有一个返回位图(“包含”二维码)的函数,我想在Image(可组合函数)中显示该位图,但我没有找到任何方法将位图转换为 aImageBitmap或仅显示该位图。

Chr*_*ris 48

根据这篇博客文章,应该可以显示如下所示的位图:

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

我自己还没有尝试过,但最近在研究使用 Jetpack Compose 显示地图时看到了这篇博客文章。


Phi*_*hov 10

线圈能够显示Bitmap内部Image

Image(
    painter = rememberAsyncImagePainter(imageBitmap),
    contentDescription = null,
)
Run Code Online (Sandbox Code Playgroud)