Conversion between android byte array, bitmap, drawable

1. Byte array to Bitmap

BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
2.Bitmap to Byte array

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

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

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




Guess you like

Origin blog.csdn.net/xifei66/article/details/54344130