标签:
==== 1
b、读取res/drawable目录下的png或者bmp
Resources r = this.getContext().getResources();
//以数据流的方式读取资源
Inputstream is = r.openRawResource(R.drawable.mm_image);
BitmapDrawable bmpDraw = new BitmapDrawable(is);
Bitmap bmp = bmpDraw.getBitmap();
如果需要利用图片解码器,如下使用:
InputStream is = getResources().openRawResource(R.drawable.icon);
Bitmap mBitmap = BitmapFactory.decodeStream(is);
Paint mPaint = new Paint();
canvas.drawBitmap(mBitmap, 40, 40, mPaint);
用Bitmap bm = BitmapFactory.decodeResource(this.getResources(), R.drawable.splash);
BitmapDrawable bd = new BitmapDrawable(this.getResources(), bm);
mBtn.setBackgroundDrawable(bd); 来代替mBtn.setBackgroundResource(R.drawable.splash)。
标签:
原文地址:http://www.cnblogs.com/awkflf11/p/5366233.html