Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does Coil support imageByteArray? #171

Closed
clint22 opened this issue Nov 14, 2019 · 3 comments
Closed

Does Coil support imageByteArray? #171

clint22 opened this issue Nov 14, 2019 · 3 comments
Labels
question A question about how to use Coil

Comments

@clint22
Copy link

clint22 commented Nov 14, 2019

When I'm trying to pass imageByteArray as a parameter into the load function it's throwing some error such as 'None of the following functions can be called with the argument supplied'. But it's working perfectly using Glide. Sharing my code snippet of what I have done using Coil and Glide.

Using Coil

val imageBytes = it.locationImage
val imageByteArray = Base64.decode(imageBytes, Base64.DEFAULT)

ivFloorMap.load(imageByteArray) {
crossfade(true)
placeholder(R.drawable.image_placeholder)
transformations(CircleCropTransformation())}

Using Glide

val imageBytes = it.locationImage
val imageByteArray = Base64.decode(imageBytes, Base64.DEFAULT)

Glide.with(context)
.asBitmap()
.dontTransform()
.placeholder(R.drawable.image_placeholder)
.load(imageByteArray)
.into(ivFloorMap)

Did anyone face the same issue?

@clint22 clint22 added the question A question about how to use Coil label Nov 14, 2019
@colinrtwhite
Copy link
Member

colinrtwhite commented Nov 14, 2019

It's not part of the base library, but it could be added pretty easily with a custom Fetcher:

class ByteArrayFetcher : Fetcher<ByteArray> {

    override fun key(data: ByteArray): String? = null

    override suspend fun fetch(
        pool: BitmapPool,
        data: ByteArray,
        size: Size,
        options: Options
    ): FetchResult {
        return SourceResult(
            source = ByteArrayInputStream(data).source().buffer(),
            mimeType = null,
            dataSource = DataSource.MEMORY
        )
    }
}

You can then add it to your ComponentRegistry when constructing the default ImageLoader. Check out here for an example.

Once that's done you can call imageView.loadAny(imageBytes) and it should work.

@clint22
Copy link
Author

clint22 commented Nov 15, 2019

Wow. It worked perfectly. Thank you.

@clint22 clint22 closed this as completed Nov 15, 2019
@ghost
Copy link

ghost commented Jul 6, 2022

For all finding this issue in 2022:
2.1.0 has added support for ByteArray, see: https://github.com/coil-kt/coil/blob/main/CHANGELOG.md#210---may-17-2022 & #1202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about how to use Coil
Projects
None yet
Development

No branches or pull requests

2 participants