-
I need to load 2 images and then combine them (like draw image one and then draw the second image at the bottom right in 1/8 of the request size). How can I do that? I can reuse fetchers in my custom fetcher, that I have found. But how do I combine those 2 images inside my custom fetcher? Any hints? Here's my fetcher so far: class LinkIconData(
val link: Link,
val overlayIconSizeFactor: Float = .25f
) {
val key: String = "LinkIconData::${link.id}::$overlayIconSizeFactor"
}
class LinkIconFetcher(
val data: LinkIconData,
private val options: Options,
private val imageLoader: ImageLoader,
) : Fetcher {
override suspend fun fetch(): FetchResult {
val url = data.link.getImage(options.context)
val urlIcon = data.link.getIcon(options.context)
if (url != null && urlIcon != null) {
val image = fetchUrl(url)
val icon = fetchUrl(urlIcon)
// TODO...
TODO()
} else if (urlIcon != null) {
return fetchUrl(urlIcon) ?: throw Exception("Error fetching urlIcon")
}else if (url != null) {
return fetchUrl(url) ?: throw Exception("Error fetching url")
} else {
throw Exception("no url or icon found")
}
}
private suspend fun fetchUrl(url: Uri) : FetchResult? {
val data = imageLoader.components.map(url, options)
val output = imageLoader.components.newFetcher(data, options, imageLoader)
val (fetcher) = checkNotNull(output) { "no supported fetcher" }
return fetcher.fetch()
}
class Factory : Fetcher.Factory<LinkIconData> {
override fun create(
data: LinkIconData,
options: Options,
imageLoader: ImageLoader,
): Fetcher {
return LinkIconFetcher(data, options, imageLoader)
}
}
class Keyer : coil.key.Keyer<LinkIconData> {
override fun key(data: LinkIconData, options: Options): String {
return data.key
}
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
MFlisar
Mar 20, 2025
Replies: 1 comment
-
Could solve it. With following function I can get drawables from the fetcher and then I can combine the drawables. fun getDrawable(options: Options, result: FetchResult?): Drawable? {
return when (result) {
is DrawableResult -> result.drawable
is SourceResult -> {
val bitmap = BitmapFactory.decodeStream(result.source.source().inputStream())
val b = when (options.scale) {
Scale.FILL -> bitmap
Scale.FIT -> scaleCenterCrop(
bitmap,
options.size.width.pxOrElse { 0 },
options.size.height.pxOrElse { 0 })
}
b.toDrawable(options.context.resources)
}
null -> null
}
} the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MFlisar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could solve it. With following function I can get drawables from the fetcher and then I can combine the drawables.