compose-imageloader icon indicating copy to clipboard operation
compose-imageloader copied to clipboard

Support for bitmap or drawable in Android target

Open klusi opened this issue 1 year ago • 1 comments

Would it be possible to provide a Bitmap or Drawable in addition to Painter when the image is successfully downloaded in Android target similar to Coil-Compose? Coil:

DisposableEffect(url) {
    val request = ImageRequest.Builder(context)
        .data(data = url)
        .target { drawable ->
            val bitmap = drawable.toBitmapOrNull() ?: return@target
            // TODO use bitmap
        }
        .build()

    val disposable = ImageLoader.Builder(context)
        .components { add(SvgDecoder.Factory()) }
        .build()
        .enqueue(request)

    onDispose {
        disposable.dispose()
    }
}

klusi avatar Jun 14 '23 16:06 klusi

you can do this:

val imageLoader = LocalImageLoader.current
LaunchedEffect(Unit) {
    val request = ImageRequest("data")
    val result = imageLoader.execute(request)
    if (result is ImageResult.Bitmap) {
        result.bitmap
    } else if (result is ImageResult.Image) {
        result.image.drawable
    } else if (result is ImageResult.Painter) {
        result.painter // svg return painter
    }
}

I think this is more simple way of looking at it and don't want to add target for now. but svg return a painter, not bitmap.

qdsfdhvh avatar Jun 15 '23 01:06 qdsfdhvh