Base64 to Bitmap in compose multiplatform?

287 Views Asked by At

I can easily convert base64 to bitmap in Android using below code

byte[] decodedString = Base64.decode(encodedImage, Base64.URL_SAFE);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);

But i can't access BitmapFactory in compose multiplatform as it belongs to android only. So how can i convert base64 to image in compose multiplatform?

1

There are 1 best solutions below

0
On

You can do it like this:

val encodedImageData = Base64.Default.decode(encodedImage)
val image = Image.makeFromEncoded(encodedImageData).toComposeImageBitmap()