views:

565

answers:

3

Hi all,

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 ?

+2  A: 

Get a bitmap decodeResource(android.content.res.Resources, int) Then either compress it to ByteArrayOutputStream() or copyPixelsToBuffer and get your array from the buffer. http://developer.android.com/reference/android/graphics/Bitmap.html

Alex Volovoy
+1  A: 
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mPhoto.compress(Bitmap.CompressFormat.JPEG /* FileType */,
                        100 /* Ratio */, stream);

HTH !

Karan
A: 

Can you say what data is stored in the stream as I can extract it into a byte array?

byte[] byteArray = stream.toByteArray() `

thx