Glance fails to load images using the coil

454 Views Asked by At

I did this in Glance to get a bitmap of the online URI for display, but it failed. Does Glance still support weight ratios?

val context = LocalContext.current val imageLoader = ImageLoader(context)
var bitmap = currentState<Bitmap>()

imageLoader.enqueue(
    ImageRequest.Builder(context)
        .data(parcelItem.artUri)
        .error(R.drawable.music)
        .target(
            onSuccess = {
                bitmap = it.toBitmap()
            },
            onError = {
                it?.let {
                    bitmap = it.toBitmap()
                }
            }
        )
        .build()
)
Image(
  provider = ImageProvider(bitmap),
  modifier = GlanceModifier.size(50.dp).cornerRadius(10.dp).padding(8.dp),
  contentDescription = ""
)

It is not possible to use the Coil directly, because the Glance component is required, and the ImageProvider(URI) does not support online resolution.

1

There are 1 best solutions below

1
On

I just need to get the Bitmap before the update and pass it to the Widget