Coil: How load an Uri into a Bitmap with no target view?

Created on 27 Apr 2020  路  5Comments  路  Source: coil-kt/coil

Hi, i am looking for the way to perform a (maybe a static?) call with Coil in order to get the response to load into a Bitmap, is it possible? I mean, i do not want to have a (mandatory) loading into a ImageView or a Drawable.

Thanks.

question

All 5 comments

You'll probably want to use a target. Something like:

val imageLoader = Coil.imageLoader(context) // or create your own instance
val request = LoadRequest.Builder(context)
    .data("scheme://my/uri")
    .target { drawable ->
        val bitmap = (drawable as BitmapDrawable).bitmap
    }
    .build()
imageLoader.execute(request)

Hi, i'm tryng compile your code but:

Coil.imageLoader -> has private access
LoadRequest.Builder can not resolve Builder

Are you using the latest Coil version (0.10.1)?

You were right!! I was using older version, now it works like a charm!!

Many thanks!!

@colinrtwhite and I are happy to help!

Was this page helpful?
0 / 5 - 0 ratings