现在的位置: 首页 > 综合 > 正文

把本地的int类型的图片转换成drawable、Bitmap

2013年01月02日 ⁄ 综合 ⁄ 共 534字 ⁄ 字号 评论关闭

获取本地图片

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对象即可。 

抱歉!评论已关闭.