Bitmap and Drawable mutual conversion method, bitmapdrawable
Many developers say they do not know how to convert Drawable and Bitmap of Android. The following two simple and efficient methods are provided.
1. Bitmap to Drawable
Bitmap bm = xxx; // xxx is obtained based on your situation
BitmapDrawable bd = BitmapDrawable (bm );
Android Development Network prompts that BtimapDrawable is a subclass of Drawable, And you can directly use the bd object.
Ii. Conversion of Drawable to Bitmap
After being converted to a Bitmap object, the Drawable object can be converted into a byte output stream through the Android SK inventory, and finally saved as jpg and png files.
Drawable d = xxx; // xxx obtain drawable based on your own situation
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd. getBitmap ();
Finally, bm is the Bitmap object we need.
How does android convert bitmap to drawable?
Bitmap to Drawable:
Bitmap bitmap = new Bitmap (...);
Drawable drawable = new BitmapDrawable (bitmap );
This should be done
In android, how does one convert the image resources in Rdrawable to Bitmap?
Bitmap bmp = BitmapFactory. decodeResource (r, R. drawable. icon );
Bitmap newb = Bitmap. createBitmap (300,300, Config. ARGB_8888 );
Canvas canvasTemp = new Canvas (newb );
CanvasTemp. drawBitmap (bmp, 50, 50, p );