天天看点

Bitmap与byte[]相互转换

Bitmap->byte[]

public byte[] BitmapToBytes(Bitmap bm) {

ByteArrayOutputStream baos = new ByteArrayOutputStream();

bm.compress(Bitmap.CompressFormat.PNG, 100, baos);

return baos.toByteArray();

}

byte[]->Bitmap

public Bitmap BytesToBimap(byte[] b) {

if (b.length != 0) {

return BitmapFactory.decodeByteArray(b, 0, b.length);

} else {

return null;

}

}