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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/q714093365/article/details/76228534

图片资源转化为Bitmap的多种方法,总有一款是你需要的微笑


方法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();




猜你喜欢

转载自blog.csdn.net/q714093365/article/details/76228534