Bitmap-called bitmaps, the general bitmap file format suffix bmp, of course, there are many encoders such as RGB565, RGB888. As a per-pixel display object, the execution efficiency is high, but the disadvantage is obvious that the storage efficiency is low. We understand that it's better to have a storage object.
drawable-as a generic graphic object for Android, it can load images in commonly used formats, such as GIF, PNG, JPG, and of course, BMP, and of course some advanced visualizations, such as gradients, graphics, etc.
I. Bitmap Turn drawable
Bitmap bm = XXX;//xxx Get it according to your situation
Bitmapdrawable bd=new bitmapdrawable (BM);
Because Btimapdrawable is a subclass of drawable, it is finally possible to use the BD object directly.
two. drawable Turn bitmap
After turning into an bitmap object, the Drawable object can be stored in a byte output stream via the SK-O-Android, and eventually it can be saved as JPG and PNG files.
Drawable d=xxx; XXX gets drawable According to his own situation
bitmapdrawable BD = (bitmapdrawable) D;
Bitmap BM = Bd.getbitmap ();
Finally, BM is the bitmap object we need.
three. Get bitmap from your resources
Public static Bitmap getbitmapfromresources (Activity Act, int resId) {
Resources res = act.getresources ();
Return Bitmapfactory.decoderesource (res, resId);
}
four. byte[] Turn bitmap
public static Bitmap Convertbytes2bimap (byte[] b) {
if (B.length = = 0) {
return null;
}
Return Bitmapfactory.decodebytearray (b, 0, b.length);
}
Five. Bitmap turn byte[]
Public Static byte[] Convertbitmap2bytes (Bitmap BM) {
Bytearrayoutputstream BAOs = new Bytearrayoutputstream ();
Bm.compress (Bitmap.CompressFormat.PNG, BAOs);
return Baos.tobytearray ();
}