Working with Base64 image in Android Studio

Asked

Viewed 1,091 times

3

I have an app in Android Studio and would like to use Base64 image in Imageview and Imagebutton.

I already know how to convert the image (from Drawable folder) to String, but I don’t know how to apply this as background to my items.

Is there how? Or is there how I take a String of a converted Base64 image on the Internet and apply as image inside Android Studio?

  • It’s not very clear to me what you want to do. I think two different problems. From what I understand, you have an image in the Drawable folder and want to put it as the background of its elements. Where does Base64 come into this? Also, you’re talking about taking a Base64 image on the Internet and applying it to your items. It’s a more concrete problem, but this is something dynamic-- it’s not something you’ll do on an Android Studio option and yes via code, right?

1 answer

5


Andiie, first you will have to convert your String Base64 for a Bitmap, and from this create a BitmapDrawable.

byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Drawable d = new BitmapDrawable(getResources(), decodedByte);

Once converted, you can use the Drawable as background.


See more here:

How to Convert a Base64 string into a Bitmap image to show it in a Imageview?

How to Convert a Bitmap to Drawable in android?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.