1. 程式人生 > >把本地的int型別的圖片轉換成drawable、Bitmap

把本地的int型別的圖片轉換成drawable、Bitmap

獲取本地圖片

Bitmap decodeResource = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_default_user_bg_34);

把本地的int型別的圖片轉換成drawable

Drawable drawable = context.getResources().getDrawable(R.drawable.left); 

把本地的int型別的圖片轉換成Bitmap 

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

Inputstream is = r.openRawResource(R.drawable.my_background_image);

BitmapDrawable  bmpDraw = new BitmapDrawable(is);

Bitmap bmp = bmpDraw.getBitmap();

Bitmap轉Drawable 

Bitmap bm=xxx; //xxx根據你的情況獲取 

BitmapDrawable bd=BitmapDrawable(bm); 

因為BtimapDrawable是Drawable的子類,最終直接使用bd物件即可。