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

后端 未结 6 2075
臣服心动
臣服心动 2020-11-22 10:23

I have a Base64 String that represents a BitMap image.

I need to transform that String into a BitMap image again to use it on a ImageView in my Android app

H

6条回答
  •  醉酒成梦
    2020-11-22 11:02

    This is a great sample:

    String base64String = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAA...";
    String base64Image = base64String.split(",")[1];
    byte[] decodedString = Base64.decode(base64Image, Base64.DEFAULT);
    Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
    imageView.setImageBitmap(decodedByte);
    

    Sample found at: https://freakycoder.com/android-notes-44-how-to-convert-base64-string-to-bitmap-53f98d5e57af

    This is the only code that worked for me in the past.

提交回复
热议问题