如何在 kotlin 中将 BitmapDrawable 或 Bitmap 转换为 ImageBitmap

Moh*_*qer 2 kotlin android-jetpack-compose

我需要更改Bitmap?BitmapDrawable显示ImageBitmap它,coil 这是我的代码

val bitmap = BlurhashDecoder.decode(blurhash, 4, 3)
Image(
    bitmap = bitmap as ImageBitmap,
    modifier = modifier,
    contentScale = ContentScale.Crop,
    contentDescription = ""
)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到此错误

java.lang.ClassCastException: android.graphics.Bitmap cannot be cast to androidx.compose.ui.graphics.ImageBitmap
Run Code Online (Sandbox Code Playgroud)

小智 7

用于bitmap.asImageBitmap()将 a 转换bitmapImageBitmap