-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Load image using bytearray #411
Comments
Actually it is not loading image from ios uri, I used compose-multiplatform-file-picker for picking the file from iOS files, then i use rememberImagePainter, it does not load image. I gets this error in the logs:
And this is the path of image which im getting from file picker and using in rememberImagePainter: |
You can add a custom Fetcher like this: class ByteArrayFetcher(
private val data: ByteArray,
) : Fetcher {
override suspend fun fetch(): FetchResult {
return FetchResult.OfSource(
source = Buffer().apply {
write(data)
}
)
}
class Factory : Fetcher.Factory {
override fun create(data: Any, options: Options): Fetcher? {
if (data !is ByteArray) return null
return ByteArrayFetcher(data)
}
}
} and then:
|
In the next version, I'll add to the default support #412 |
@qdsfdhvh And how we can use it? Like this with custom request and imageLoader in rememberImagePainter: ` val imageLoader = ImageLoader {
|
In addition to configuring it in ImageLoader, you can also configure it directly in ImageRequest, like this: val request = remember {
ImageRequest(data = byteArray) {
components {
add(ByteArrayFetcher.Factory())
}
}
}
Image(
painter = rememberImagePainter(request),
// ...
) in version |
Ok @qdsfdhvh huge thanks. |
Hi @qdsfdhvh i tried it, But its not working, not sure if issue is with compose-multiplatform-file-picker get byte array logic or its with compose image loader. Did u tried it yourself? |
Hi @sunildhiman90 , ByteArray should work fine, but there seems to be something wrong with MPFile.getFileByteArray() when I test it, so i used |
@qdsfdhvh I tried using platformFile as well, its also not working. So how can i load that image now from iOS file picker using compose image loader? |
use version |
Thanks @qdsfdhvh, its working fine that way as u mentioned in version 1.7.3 and with MPFile.platformFile. One question here, suppose i want to get the byte array of this image in base64 format, then how can i do that by any way or by any library in compose multiplatform, any idea? |
Maybe need to manually extend |
Hi one question here, why didnt you made these changes with compose multiplatform version 1.5.11 instead of 1.6.0-dev1334 ? |
Mainly because of the dependency on |
Hi,
Can we load image from ByteArray in compose imageloader?
if yes how we can do that?
Thanks
The text was updated successfully, but these errors were encountered: