我会尽力协助您进行翻译。以下是需要翻译的内容:
有需要帮助的地方吗?
我正在尝试将位图编码和解码为字节数组,但不使用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;
}
有需要帮助的地方吗?