Android处理Drawable中的图片
android加载图片有两种方式
一种是int,一种是Drawable
使用例子:
imageView设置背景
setBackgroundResource(R.drawable.icon);
setBackgroundDrawable(this.getResources().getDrawable(R.drawable.icon));
setBackground(drawable);
将Drawable转换为BitMap
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、
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);