Many developers say they don't know how to convert relatedly between Android's Drawable and Bitmap. Here are two simple and efficient methods for Android 123.
1. Bitmap to Drawable
Copy the codeThe code is as follows:
Bitmap bm=xxx; //xxx obtains it according to your situation
BitmapDrawable bd=BitmapDrawable(bm);
Android Development Network prompts that because BtimapDrawable is a subclass of Drawable, you can use the bd object directly in the end.
2. Drawable to Bitmap
After converting it to a Bitmap object, the Drawable object can be stored into a byte output stream through Android's SK inventory, and finally it can be saved into jpg and png files.
Copy the codeThe code is as follows:
Drawable d=xxx; //xxx obtain drawable according to your own situation
BitmapDrawable bd = (BitmapDrawable) d;
Bitmap bm = ();
In the end, bm is the Bitmap object we need.