1. 程式人生 > >將圖片資源轉化為Bitmap的多種方法

將圖片資源轉化為Bitmap的多種方法

圖片資源轉化為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();