Many developers say they do not know how to convert Drawable and Bitmap of Android. The following two simple and efficient methods are provided by Android123.
1. Bitmap to Drawable
Copy codeThe Code is as follows: 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.
Copy codeThe Code is as follows: Drawable d = xxx; // xxx obtains drawable based on your own situation.
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = bd. getBitmap ();
Finally, bm is the Bitmap object we need.