我想将位图写入 sdcard 使用 byte[] 遵循以下代码:(我不想使用“ Bitmap.compress(...) ”,因为 .PNG 非常慢)。
Bitmap bmp;
// Convert bitmap -> Byte[]
byte[] byteArray = bitmapToByteArray(bmp);
// convert byte[] -> inputstream
InputStream inStream = new ByteArrayInputStream(byteArray);
FileOutputStream fos = new FileOutputStream(pathFile);
int b;
byte[] d = new byte[4096];
while ((b = inStream.read(d)) != -1) {
fosX.write(d, 0, b);
}
// Function convert bitmap -> byte[]
public static byte[] bitmapToByteArray(Bitmap bm) {
int bytes = bm.getWidth()*bm.getHeight()*4;
ByteBuffer buffer = ByteBuffer.allocate(bytes);
bm.copyPixelsToBuffer(buffer);
byte[] array = buffer.array();
return array;
}
写入后的文件位图错误。请