android获取bitmap的方法
第一种方法
通过BitmapDrawable对象获得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
InputStream is = getResources().openRawResource(R.drawable.icon); Bitmap mBitmap = BitmapFactory.decodeStream(is);
第三种方法
((BitmapDrawable) context.getResources().getDrawable(id)).getBitmap()
其中第一、二种方法获取的bitmap对象的width、height保持原大小
第三种方法获取的bitmap对象的width、height为原始大小X机器density
参考资料:
http://www.eoeandroid.com/thread-90388-1-1.html
相关推荐
  调调    2013-07-24  
   博了个客    2020-05-31  
   lixiaotao    2020-03-05  
   songfens    2020-01-10  
   MIKUScallion    2020-01-10  
   83580494    2013-06-29  
   TongsengsBlog    2013-08-27  
   Android进阶    2013-08-25  
   89143951    2011-08-25  
   八角塘塘主    2019-10-29  
   lerayZhang    2015-01-11  
   timewind    2019-07-01  
   Ashes    2019-06-30  
   learningITwell    2019-06-28  
   PGzxc    2019-06-28  
   xusong    2012-08-01  
   Android进阶    2019-06-27  
   helowken    2019-06-21  
   飞奔的熊猫    2019-06-21