Transfer from http://blog.csdn.net/june5253/article/details/7826597
1, bitmap-->drawable
Bitmap Drawable2bitmap (drawable drawable) {if(drawableinstanceofbitmapdrawable) { return((bitmapdrawable) drawable). Getbitmap (); } Else if(drawableinstanceofninepatchdrawable) {Bitmap Bitmap=Bitmap. CreateBitmap (Drawable.getintrinsicwidth (), Drawable.getintrinsicheight (), drawable.getopacity ()! = Pixelformat.opaque?Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565); Canvas Canvas=NewCanvas (bitmap); Drawable.setbounds (0, 0, Drawable.getintrinsicwidth (), Drawable.getintrinsicheight ()); Drawable.draw (canvas); returnbitmap; } Else { return NULL; } }
2. Drawable-->bitmap obtained from the resources
Bitmap Bitmap=bitmapfactory.decoderesource (res,r.drawable.pic);
3, Bitmap-->drawable
drawable bitmap2drawable (Bitmap Bitmap) { new bitmapdrawable (Bitmap); }
4, bitmap-->byte[]
byte [] bitmap2bytes (Bitmap BM) { new bytearrayoutputstream (); , BAOs); return Baos.tobytearray (); }
5, Byte[]-->bitmap
Bitmap bytes2bimap (byte[] b) { if (b.length! = 0) {return Bitmapfactory.decodebytearray (b, 0, b.length); Else { returnnull; } }
Conversion between Android drawable, Bitmap, byte[]