android - 如何将Drawable转换为位图?

我想设置一个特定的Drawable作为设备的墙纸,但所有墙纸功能只接受Bitmaps。我不能使用WallpaperManager因为我是2.1之前的。
另外,我的抽屉是从网络下载的,不在R.drawable中。


最佳答案:

这段代码有帮助。

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

这里是下载图片的版本。
String name = c.getString(str_url);
URL url_value = new URL(name);
ImageView profile = (ImageView)v.findViewById(R.id.vdo_icon);
if (profile != null) {
    Bitmap mIcon1 =
        BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
    profile.setImageBitmap(mIcon1);
}