Home > other >  how to convert BitmapDrawable or Bitmap to ImageBitmap in kotlin
how to convert BitmapDrawable or Bitmap to ImageBitmap in kotlin

Time:04-20

I need to change Bitmap? or BitmapDrawable to ImageBitmap and show it with coil here is my code

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

when I run it I get this error

java.lang.ClassCastException: android.graphics.Bitmap cannot be cast to androidx.compose.ui.graphics.ImageBitmap

CodePudding user response:

use bitmap.asImageBitmap() to convert a bitmap to ImageBitmap

  • Related