android将drawable下的图片转换成bitmap

时间:2023-02-09 17:01:08

将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);