Is there a way to convert bitmap to byte array without the Bitmap.CompressFormat class in Android? if not, how comes? if its is possible, please let me know how, thanx
Asked
Active
Viewed 7,768 times
1 Answers
1
Something like this?
//b is the Bitmap
//calculate how many bytes our image consists of.
int bytes = b.getByteCount();
//or we can calculate bytes this way. Use a different value than 4 if you don't use 32bit images.
//int bytes = b.getWidth()*b.getHeight()*4;
ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
b.copyPixelsToBuffer(buffer); //Move the byte data to the buffer
byte[] array = buffer.array(); //Get the underlying array containing the data.

Community
- 1
- 1

Stefan de Bruijn
- 6,289
- 2
- 23
- 31
-
is it possible to save this array as jpg without using the Bitmap.CompressFormat? @Stephan – Julie Jun 10 '13 at 13:12