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);

更多相关文章

  1. android- activity,Application,activity渲染xml文件
  2. Android 文件操作大全
  3. android中加载assets中的资源文件
  4. Android开发 - 丰富常用的颜色文件colors.xml
  5. 学习Android之setDataAndType(利用第三方应用程序打开各种文件)
  6. 根据文件名称修改安卓默认的蓝牙接收文件地址

随机推荐

  1. adnroid(10)(android下的单元测试)
  2. android之壁纸机制
  3. Android使用AsyncTask下载图片并显示进度
  4. Android(安卓)Tools
  5. Android(安卓)显示系统 --- Surface Flin
  6. Android中文API —— VideoView
  7. 下半年我想做的事
  8. Android(安卓)Studio导入Android平台源码
  9. android异步的几种方式
  10. android 编译模块