学而实习之 不亦乐乎

Android 将图片资源转化为 Bitmap 的多种方法

2023-08-14 08:06:14

方法1:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.mingchuseal, newOpts);

方法2:

Drawable drawable = getResources().getDrawable(R.mipmap.mingchuseal);
BitmapDrawable bd = (BitmapDrawable) drawable;
final Bitmap bmm = bd.getBitmap();

方法3:

InputStream is = getResources().openRawResource(R.drawable.icon);  
Bitmap mBitmap = BitmapFactory.decodeStream(is);

方法4:

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

方法5:

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