将 Java 位图转换为字节数组
2022-08-31 05:03:17
Bitmap bmp = intent.getExtras().get("data");
int size = bmp.getRowBytes() * bmp.getHeight();
ByteBuffer b = ByteBuffer.allocate(size);
bmp.copyPixelsToBuffer(b);
byte[] bytes = new byte[size];
try {
b.get(bytes, 0, bytes.length);
} catch (BufferUnderflowException e) {
// always happens
}
// do something with byte[]
当我查看缓冲区后,对字节的调用都是0...从相机返回的位图是不可变的...但这并不重要,因为它正在做一个副本。copyPixelsToBuffer
此代码可能有什么问题?