How to convert a Drawable to a Bitmap?

前端 未结 20 2443
攒了一身酷
攒了一身酷 2020-11-21 22:46

I would like to set a certain Drawable as the device\'s wallpaper, but all wallpaper functions accept Bitmaps only. I cannot use WallpaperMan

20条回答
  •  清酒与你
    2020-11-21 23:10

    This piece of code helps.

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

    Here a version where the image gets downloaded.

    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);
    }
    

提交回复
热议问题