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();
}

猜你喜欢

转载自jykenan.iteye.com/blog/1697808