資源文件轉換成Drawable或Bitmap

1、

Resources resources = mContext.getResources();
Drawable drawable = resources.getDrawable(R.drawable.a);
imageview.setBackground(drawable);

2、

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

3、

Bitmap bmp=BitmapFactory.decodeResource(r, R.drawable.icon);

Bitmap newb = Bitmap.createBitmap( 300, 300, Config.ARGB_8888 ); 

4、

InputStream is = getResources().openRawResource(R.drawable.icon);  

Bitmap mBitmap = BitmapFactory.decodeStream(is);

發佈了16 篇原創文章 · 獲贊 1 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章