Working with Base64 image in Android Studio

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 the Drawable folder) to String, but I do not know how to apply this as a background for my items.

Is there such a thing as? Or is there a way to get a String from a converted base64 image on the same Internet and apply it as an image inside Android Studio?

    
asked by anonymous 25.06.2016 / 07:16

1 answer

5

Andiie, you'll first have to convert your Base64 String to a Bitmap , and from that 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 Drawable as background .

See more here:

How to convert the Base64 string into a Bitmap image to show it in a ImageView?

How to convert Bitmap to Drawable in android?

    
25.06.2016 / 16:38