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的Listview用法总结和Adapter的使用
  5. Android(安卓)Dex文件结构
  6. Android传感器
  7. android- activity,Application,activity渲染xml文件
  8. android_Server_Socket_通信序列化实现
  9. 运行时改变Button的android:drawableTop

随机推荐

  1. Android(安卓)自定义缩短Toast显示时间
  2. android和vue交互之js调取原生安卓扫码库
  3. Android Http Server
  4. android_error
  5. 在android真机上使用sqlite3
  6. 《Android/OPhone 开发完全讲义》已出版,
  7. Android 中文 API (23) ―― MultiAutoComp
  8. 启动emulator出错
  9. Android设置多个闹钟
  10. 64位win7操作系统 Android(安卓)开发环境