R.drawable.***中的文件是我们常用到的,不过有时候又没有直接的方法通过R文件获得图片,这时候就需要我们直接来转换一下了
下面提供四种方法给大家参考:
1、
Resources resources = mContext.getResources();
Drawable drawable = resources.getDrawable(R.drawable.***);
2、
Resources resources = this.getContext().getResources();
Inputstream is = resources .openRawResource(R.drawable***);
BitmapDrawable bmpDraw = new BitmapDrawable(is);
Bitmap bmp = bmpDraw.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);
Android基础之R.drawable.***生成Drawa与Bitmap
时间: 2024-11-09 04:45:35