android 获取Bit地图 的两种方法

android 获取Bitmap 的两种方法
  这里我直接贴代码了。
  第一种方法
//得到Resources对象
Resources r = this.getContext().getResources();
//以数据流的方式读取资源
Inputstream is = r.openRawResource(R.drawable.my_background_image);
BitmapDrawable  bmpDraw = new BitmapDrawable(is);
Bitmap bmp = bmpDraw.getBitmap();


  第二种方法这种方法是通过BitmapFactory这个工具类,BitmapFactory的所有函数都是static,这个辅助类可以通过资源ID、路径、文件、数据流等方式来获取位图。大家可以打开API 看一下里边全是静态方法。这个类里边有一个叫做 decodeStream(InputStream is)  
此方法可以 解码一个新的位图从一个InputStream。这是获得资源的InputStream。
代码:
InputStream is = getResources().openRawResource(R.drawable.icon);  
         Bitmap mBitmap = BitmapFactory.decodeStream(is);  
         Paint mPaint = new Paint();  
         canvas.drawBitmap(mBitmap, 40, 40, mPaint);  


   显然第二种方法简单很多了。  如果大家对 android的 画图还是不熟悉的话 就去看我推荐的文章吧,仔细看一定可以学会的。在这里http://byandby.iteye.com/blog/827527