【发布时间】:2014-06-08 02:02:12
【问题描述】:
我不是位图新手,也不是 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
}
但这很慢(比以前慢):(
拜托,谁能给个更快的方法?引导我...
【问题讨论】:
-
这个问题不是任何其他问题的副本。它与优化和寻找最佳技术有关。而且我做了很好的研究。
-
您好,您能分享一下您的发现吗?到目前为止,您分析的哪个更快。
-
@vrs 第一种方法更好。我刚刚发现你压缩得越多,花费的时间就越多。但与后者相比,后者肯定需要更多时间。
标签: java android optimization bitmap