How to get an array of bytes from a resource that can be used?

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

Does anyone know how to do this?

+4
source share
3 answers

Get a 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

+6
source
  Drawable drawable; Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] bitmapdata = stream.toByteArray(); 
+9
source
 ByteArrayOutputStream stream = new ByteArrayOutputStream(); mPhoto.compress(Bitmap.CompressFormat.JPEG /* FileType */, 100 /* Ratio */, stream); 

Hth!

+2
source

Source: https://habr.com/ru/post/1309693/


All Articles