I'm attempting to display a PNG image encoded as a Base64 string in an Android app using Coil, but nothing shows up. My Base64 string starts like this:
data:image/png;base64,iVBORw0KGgo...
and I'm trying to decode and display using Coil.
Here's the code snippet:
val base64ImageString = "data:image/png;base64,iVBORw0KGgo..." // Your Base64 string here
val imageLoader = ImageLoader(context)
val request = ImageRequest.Builder(context)
.data(base64ImageString)
.target(imageView)
.build()
imageLoader.enqueue(request)
I discovered the issue was due to not properly stripping the data:image/png;base64, prefix before decoding the Base64 string. Here’s the corrected approach: