Android中通过资源文件获取drawable的几种方法
16lz
2021-01-23
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);
更多相关文章
- android- activity,Application,activity渲染xml文件
- Android 文件操作大全
- android中加载assets中的资源文件
- Android开发 - 丰富常用的颜色文件colors.xml
- 学习Android之setDataAndType(利用第三方应用程序打开各种文件)
- 根据文件名称修改安卓默认的蓝牙接收文件地址