Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a byte array from a drawable resource ?

I would like to get a byte array from an jpeg image located in my res/drawable file ?

Does anyone know how to do that please ?

like image 686
Spredzy Avatar asked Nov 30 '22 10:11

Spredzy


1 Answers

    Drawable drawable;

    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] bitmapdata = stream.toByteArray();
like image 200
Sandy Avatar answered Dec 04 '22 02:12

Sandy