Convert string base64 into an image on android

0

I have the string code of a base64 image, the problem is this code I need to pass it to image, I have seen that online platforms make it perfect, but in Android? how could you insert this base64 code and turn it into an image showing it in ImageView.

I was using this but it did not work:

 TextView tv = (TextView)findViewById(R.id.textView);
    tv.buildDrawingCache();
    ImageView img = (ImageView)findViewById(R.id.imageView);
    img.setImageBitmap(tv.getDrawingCache());

The format is: image / tiff

    
asked by DoubleM 08.01.2018 в 23:02
source

1 answer

0

See if this can help you:

    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);

References:

link

link

Example: link

    
answered by 09.01.2018 в 06:57