Android-based R. drawable. *** generate Drawa and Bitmap
Files in R. drawable. *** are commonly used, but sometimes there is no direct way to obtain images through the R file. At this time, we need to directly convert them.
The following provides four methods for your reference:
1,
Resources resources = mContext. getResources ();
Drawable drawable = resources. getDrawable (R. drawable .***);
2,
Resources resources = this. getContext (). getResources ();
Inputstream is = resources. openRawResource (R. drawable ***);
BitmapDrawable BMP draw = new BitmapDrawable (is );
Bitmap bmp = bmp draw. getBitmap ();
3,
Resources resources = this. getContext (). getResources ();
Bitmap bmp = BitmapFactory. decodeResource (resources, R. drawable .***);
Bitmap newb = Bitmap. createBitmap (300,300, Config. ARGB_8888 );
4,
InputStream is = getResources (). openRawResource (R. drawable .***);
Bitmap mBitmap = BitmapFactory. decodeStream (is );