Skip to content Skip to sidebar Skip to footer

How To Create A Drawable From Byte[] ? (android)

I have an array of bytes and I need to convert it into a Android Drawable. How can I perform this conversion? Here is what i tried but without success: byte[] b = getByteArray(); B

Solution 1:

If your byte[] b is contains imagedata then you can also try this,

Drawableimage=newBitmapDrawable(BitmapFactory.decodeByteArray(b, 0, b.length));

EDIT

BitmapDrawable constructor without Resources is now deprecated, So use this instead:

Drawableimage=newBitmapDrawable(getResources(),BitmapFactory.decodeByteArray(b, 0, b.length));

Try this and let me know what happen,

Solution 2:

Do you really need a Drawable ? If Bitmap can fit, then :

Bitmap bitmap = BitmapFactory.decodeStream(is);

Post a Comment for "How To Create A Drawable From Byte[] ? (android)"