android将drawable下的图片转换成bitmap

Posted 野路子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android将drawable下的图片转换成bitmap相关的知识,希望对你有一定的参考价值。

将drawable下的图片转换成bitmap

1、 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.xxx);

2、Resources r = this.getContext().getResources();
      Inputstream is = r.openRawResource(R.drawable.xxx);
      BitmapDrawable  bmpDraw = new BitmapDrawable(is);
      Bitmap bmp = bmpDraw.getBitmap();

3、Resources r = this.getContext().getResources();

      Bitmap bmp=BitmapFactory.decodeResource(r, R.drawable.icon);
      Bitmap bmp = Bitmap.createBitmap( 300, 300, Config.ARGB_8888 );

将drawable下的图片转换成Drawable

Resources resources = mContext.getResources();
Drawable drawable = resources.getDrawable(R.drawable.a);
imageview.setBackground(drawable);







以上是关于android将drawable下的图片转换成bitmap的主要内容,如果未能解决你的问题,请参考以下文章