android byte数组,bitmap,drawable之间的转换

1.Byte数组转Bitmap

BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
2.Bitmap转Byte数组

ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
bytes = baos.toByteArray();
3.Drawable转Bitmap

Drawable d=xxx; //xxx根据自己的情况获取drawable
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd.getBitmap();
4.Bitmap转Drawable

Bitmap bm=xxx; //xxx指获取的bitmap
BitmapDrawable bd=BitmapDrawable(bm);




你可能感兴趣的:(Android)