【问题标题】:How can I display a bitmap in Compose Image如何在 Compose Image 中显示位图
【发布时间】:2021-10-23 14:39:03
【问题描述】:

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

【问题讨论】:

    标签: android-jetpack-compose android-bitmap android-image


    【解决方案1】:

    基于this blog post,应该可以显示这样的位图:

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

    我自己没有尝试过,但最近在研究使用 Jetpack Compose 显示地图时偶然发现了这篇博文。

    【讨论】:

    • 工作就像一个魅力,谢谢:)
    【解决方案2】:

    Coil 能够在Image 内显示Bitmap

    Image(
        painter = rememberImagePainter(imageBitmap),
        contentDescription = null,
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多