您的位置:首页 > 移动开发 > Android开发

android获取资源文件R.drawable中的图片的相关方法

2014-06-03 16:30 639 查看
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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: