Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display byte[] to ImageView in Android

Tags:

Is it possible to do this? I'm reading an XML file that has the Base64 string of an image. I'm planning to use Base64.decode to have the byte array of the image string. I'm stuck though on how to use it in an ImageView. Do i have to create a 'drawable' class first then set it to ImageView's src property?

Thanks!

like image 604
firnnauriel Avatar asked Aug 23 '10 07:08

firnnauriel


2 Answers

In case anyone else stumbles across this question, here is the code

import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.widget.ImageView;  public class ModelAssistant {      public static void setImageViewWithByteArray(ImageView view, byte[] data) {         Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);         view.setImageBitmap(bitmap);     } } 
like image 151
RobCroll Avatar answered Oct 07 '22 12:10

RobCroll


You can use BitmapFactory.decodeByteArray() to perform the decoding.

like image 25
Romain Guy Avatar answered Oct 07 '22 14:10

Romain Guy