我不是Bitmap和Java的新手。我正在尝试在循环中将高分辨率位图转换为字节数组。请查看此处的代码:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, stream);
imageByteArray = stream.toByteArray();
当我使用上述方法时,我能够在1秒内转换5张图片。但是我需要更快的速度。我也尝试了像这样使用ByteBuffer
的方法:
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
}
但是这很慢(比以前更慢):(
请问有更快的方法吗?指引我一下...