1、Drawable → Bitmap
Resources res=getResources();
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.sample_0);
public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(
drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(),
drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
//canvas.setBitmap(bitmap);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
Drawable drawable =new BitmapDrawable(bmp);
<span style="white-space:pre"> </span>private byte[] Bitmap2Bytes(Bitmap bm) {
<span style="white-space:pre"> </span>ByteArrayOutputStream baos = new ByteArrayOutputStream();
<span style="white-space:pre"> </span>bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
<span style="white-space:pre"> </span>return baos.toByteArray();
<span style="white-space:pre"> </span>}
4、 Byte[] → Bitmap
<span style="white-space:pre"> </span>private Bitmap Bytes2Bimap(byte[] b) {
<span style="white-space:pre"> </span>if (b.length != 0) {
<span style="white-space:pre"> </span>return BitmapFactory.decodeByteArray(b, 0, b.length);
<span style="white-space:pre"> </span>} else {
<span style="white-space:pre"> </span>return null;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}