android如何获取res文件夹下drawable文件夹下的图片资源

android 如何获取 res ⽂件夹下 drawable ⽂件夹下的图⽚资源⼀、前⾔:我们在项⽬中有时候会遇到要⽤代码或drawable下⾯的图⽚资源,我们就可以使⽤以下⽅法获取:1、 在Ac

android如何获取res⽂件夹下drawable⽂件夹下的图⽚资源 ⼀、前⾔: 我 们 在 项 ⽬ 中 有 时 候 会 遇 到 要 ⽤ 代 码 或 d r a w a b l e 下 ⾯ 的 图 ⽚ 资 源 , 我 们 就 可 以 使 ⽤ 以 下 ⽅ 法 获 取 : 1、在Activity中: Bitmapbm=BitmapFactory.decodeResource(getResources(),R.drawable.img); 2、在Fraagmenntt或者者其其它它类类中中:: Bitmapbitmap=BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_launcher); ⼆、其它⽅式可以参考: 1、⽅式⼀: Resourcesresources=mContext.getResources(); Drawabledrawable=resources.getDrawable(R.drawable.a); imageview.setBackground(drawable); 2、⽅式⼆: Resourcesr=this.getContext().getResources(); Inputstreamis=r.openRawResource(R.drawable.my_background_image); BitmapDrawablebmpDraw=newBitmapDrawable(is); Bitmapbmp=bmpDraw.getBitmap(); 3、⽅式三: Resourcesr=this.getContext().getResources(); Bitmapbmp=BitmapFactory.decodeResource(r,R.drawable.icon); Bitmapnewb=Bitmap.createBitmap(300,300,Config.ARGB_8888); 4、⽅式四: InputStreamis=getResources().openRawResource(R.drawable.icon); BitmapmBitmap=BitmapFactory.decodeStream(is);

腾讯文库android如何获取res文件夹下drawable文件夹下的图片资源