Android基础之R.drawable.***生成Drawa与Bitmap

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,布布扣,bubuko.com

Android基础之R.drawable.***生成Drawa与Bitmap

上一篇:用正则表达式抓取网页中的ul 和 li标签中最终的值!


下一篇:[Android_项目]Android开源项目分类汇总