android 获取资源文件 r.drawable中的图片转换为drawable、bitmap

来源:互联网 发布:易语言创建mysql数据库 编辑:程序博客网 时间:2024/04/29 04:55

android 获取资源文件 r.drawable中的图片转换为drawable、bitmap

转载自http://cfanz.cn/index.php?c=article&a=read&id=141146

1、

Resources resources = mContext.getResources();
Drawable drawable = resources.getDrawable(R.drawable.a);
imageview.setBackground(drawable);

2、

Resources r = this.getContext().getResources();
Inputstream is = r.openRawResource(R.drawable.my_background_image);
BitmapDrawable  bmpDraw = new BitmapDrawable(is);
Bitmap bmp = bmpDraw.getBitmap();

3、

Bitmap bmp=BitmapFactory.decodeResource(r, R.drawable.icon);

Bitmap newb = Bitmap.createBitmap( 300, 300, Config.ARGB_8888 ); 

4、

InputStream is = getResources().openRawResource(R.drawable.icon);  

Bitmap mBitmap = BitmapFactory.decodeStream(is);

2 0
原创粉丝点击