简体   繁体   中英

How to set image in ImageView from BASE64 string reciveb dy JSON

I have something like:

JSONArray Icons      = new JSONArray();

In AsyncTask I'm reciving images in BASE64 from Flask server:

Icons      = (JSONArray) result.get("Icons");

Now I need to update ImageView with images that are stored in JSONArray in BASE64. It should be something like:

imageView.setImageBitmap(Icons.get(i)...)

You can decode the base64 image and set in imageView like this:

byte[] decodedString = Base64.decode(strBase64, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); 
image.setImageBitmap(decodedByte);

Also, check whether you're receiving a valid base64 string before setting it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM