1

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.

花未开
  • 159
  • 1
  • 6

1 Answers1

1

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

花未开
  • 159
  • 1
  • 6
  • I'm also curious about this, but so far couldn't find any reference if we can update images from remote url. Did you have any luck? – Elias Bellido May 23 '22 at 22:48