bitmap与byte[]相互装换

1.bitmap-->byte[]

private byte[] bitmap2Bytes(Bitmap bm){

ByteArrayOutputStream baos = new ByteArrayOutputStream();

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

return baos.toByteArray();  

}

2.byte[] 装换成Bitmap

private Bitmap byte2Bitmap(byte[] b){

if(b.length != 0){

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

} else{

return null;

}

}


你可能感兴趣的:(android)