将位图转换为字节数组,不使用Bitmap.CompressFormat

4
有没有一种在Android中不使用Bitmap.CompressFormat类将位图转换为字节数组的方法?如果没有,为什么?如果可以,请告诉我如何做,谢谢。
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.

来自:https://dev59.com/Tmkw5IYBdhLWcg3wBl-A#10192092


可以在不使用Bitmap.CompressFormat的情况下将此数组保存为jpg吗?@Stephan - Julie

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接