Drawable --> bitmap
Public static bitmap drawabletobitmap (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;
}
Bitmap --> byte []
Private byte [] bitmap2bytes (Bitmap BM ){
Bytearrayoutputstream baos = new bytearrayoutputstream ();
BM. Compress (bitmap. compressformat. PNG, 100, baos );
Return baos. tobytearray ();
}
Private byte [] bitmap2bytes (Bitmap BM ){
Bytearrayoutputstream baos = new bytearrayoutputstream ();
BM. Compress (bitmap. compressformat. PNG, 100, baos );
Return baos. tobytearray ();
}
Byte [] --> bitmap
Private bitmap bytes2bimap (byte [] B ){
If (B. length! = 0 ){
Return bitmapfactory. decodebytearray (B, 0, B. Length );
}
Else {
Return NULL;
}
}