views:

1510

answers:

2

How can I convert a Drawable to a Bitmap?
I would like to set a certain drawable as the device's wallpaper, but all wallpaper functions accept Bitmaps only (I cannot use WallpaperManager - I'm pre 2.1).
Also, my drawables are downloaded from the web and do not reside in R.drawable.

Thanks, Rob

+1  A: 
Bitmap icon= BitmapFactory.decodeResource(context.getResources(),
                    R.drawable.icon_resource);

this piece of code helps.

Edit:

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);
Praveen Chandrasekaran
Hi Praveen. The drawable I want to set as the wallpaper is not in R.drawable. It is a drawable I downloaded from the web and keep it in an arrayList of type Drawable along with other drawables.
Rob
i think you have the url values. then my edited answer should help.
Praveen Chandrasekaran
where does str_url come from? I couldn't find any Drawable function related to strings... thanks for your help.
Rob
I think I found something: if "draw" is the drawable I want to convert to a bitmap then: Bitmap bitmap = ((BitmapDrawable)draw).getBitmap();does the trick!
Rob
A: 

Drawable d = ImagesArrayList.get(0);
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();

this converts from Drawable to Bitmap...

Rob