Let's talk about the conversion between Resource, Drawable and Bitmap, and drawablebitmap.
It is better to sort these items into different categories.
Resource-> Drawable
Drawable draw1 = this.getResources().getDrawable(R.drawable.icon);
Drawable-> Bitmap
1.
Static Bitmap drawableToBitmap (Drawable drawable) // converts drawable to bitmap {int width = drawable. getIntrinsicWidth (); // retrieves the length and width of the drawable int height = drawable. getIntrinsicHeight (); Bitmap. config config = drawable. getOpacity ()! = PixelFormat. OPAQUE? Bitmap. config. ARGB_8888: Bitmap. config. RGB_565; // obtain the drawable color format Bitmap bitmap = Bitmap. createBitmap (width, height, config); // create the corresponding bitmap Canvas canvas = new Canvas (bitmap); // create the Canvas drawable for the corresponding bitmap. setBounds (0, 0, width, height); drawable. draw (canvas); // draw the drawable content to the canvas and return bitmap ;}
2.
Bitmap bitmap = ((android.graphics.drawable.BitmapDrawable) pm.getApplicationIcon(appInfo)).getBitmap();
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 );