android 获取资源文件 r.drawable中的图片转换为drawable、bitmap

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_37160260/article/details/79962197

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



阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页