byte,drawable,bitmap图片相互转换

private Drawable Bytes2Drawable(byte[] b) {
if (b.length != 0) {
Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
Drawable drawable = new BitmapDrawable(bitmap);
return drawable;
} else {
return null;
}
}


private byte[] drawableToByte(int position){
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
mThumbIds[position]);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
}


private byte[] bitmapToByte(Bitmap bm) {
Bitmap bmp = bm;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 30, baos);
return baos.toByteArray();
}

你可能感兴趣的:(drawable)