有没有办法将位图转换为字节数组而无需 Android 中的 Bitmap.CompressFormat 类?如果没有,怎么会?如果可能的话,请告诉我怎么做,thanx
问问题
7538 次
1 回答
1
像这样的东西?
//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.
于 2013-06-10T12:17:39.470 回答