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. NPM 和webpack 的基础使用
  2. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  3. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
  4. Android系统进程Zygote启动过程的源代码分析(2)
  5. 从J2EE转向Android的第九天-----文件存储
  6. android 读 txt
  7. Android编译系统(Android.mk文件详解-仅供参考)
  8. 如何在Activity调用surfaceView实现透明或半透明的效果
  9. Android(安卓)Studio 应用目录结构说明

随机推荐

  1. android 获取Gps信息的程序源码
  2. Android 使用 TableLayout 布局拉伸宽度
  3. Apple 再挑起戰火,控告 Samsung 15款 Andr
  4. Android撸一个转盘抽奖
  5. android 中隐藏EditText的下划线方法
  6. android:configChanges属性
  7. Android 线程超时的例子
  8. Tips: compilation and creating new pro
  9. Android应用在未启动的情况下无法收到指
  10. 一个现有Android工程作为组件加入到另一