【发布时间】:2014-09-14 15:29:30
【问题描述】:
我正在尝试在不使用 bitmap.compress 的情况下将位图编码和解码为字节数组,但是当我解码数组时,BitmapFactory.decodeByteArray 始终返回 NULL
编码方式如下:
public byte[] ToArray(Bitmap b)
{
int bytes = b.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
b.copyPixelsToBuffer(buffer); //Move the byte data to the buffer
// DECODE
String imgString = Base64.encodeToString(buffer.array(), Base64.NO_WRAP);
byte[] ret = Base64.decode(imgString, Base64.DEFAULT);
imgString = null;
return ret;
}
有什么帮助吗?
【问题讨论】:
-
为什么不使用 100% 质量的压缩?我假设这里关心的是图像的质量?
-
@Ali 如果您已经有效地创建了位图并打算将其存储在数据库中,那么再次压缩它是多余的。
标签: android bitmap base64 bytearray