Drawable -> Bitmap... (bitmap2drawable is OK..)

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Drawable -> Bitmap... (bitmap2drawable is OK..)

Postby Profete162 » Tue Jan 12, 2010 7:40 pm

Hello.

I recently read some tutorials where i can transform a Bitmap ressource into a drawable ressource by BitmapDrawable method or this code.

Code: Select all
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);


So, that's OK.. no problem at all!







But now, i am getting a drawable by using: Drawable getApplicationIcon (ApplicationInfo info) and i want tu put this icon on a canvas using:

canvas.drawBitmap(myBitmap,X, Y, null);


So the problem is that i cannot transform easily a Drawable into a Bitmap.



Please tell me how to do that please, i really need this code i a am looking for days!


Thank a lot.
Profete162
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Nov 27, 2009 6:07 pm

Top

Postby jwei512 » Tue Jan 12, 2010 8:02 pm

Have you checked out:

http://developer.android.com/reference/ ... wable.html

?

It seems like you can get the application icon as a Resource using its id, and get the bitmap from that so you don't actually need to turn it into a drawable.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby Profete162 » Tue Jan 12, 2010 8:18 pm

Thank for your answer.

In fact I need any icon ( like taskiller or taskswitcher) si i really need a drawable, i have no choice because the method getApplicationIcon is only drawable. I know how to get my app icon into bitmap.



I my first post, i talked about BitmapDrawable ( 3rd line). That i currently use to transform a bitmap into drawable. But i don't think it's possible in the reverse way ( drawable to bitmap)

Therefore, thank for you help. It's nice to see people here to help.
Profete162
Experienced Developer
Experienced Developer
 
Posts: 67
Joined: Fri Nov 27, 2009 6:07 pm

Re: Drawable -> Bitmap... (bitmap2drawable is OK..)

Postby pskink » Fri Feb 05, 2010 9:57 am

Profete162 wrote:But now, i am getting a drawable by using: Drawable getApplicationIcon (ApplicationInfo info) and i want tu put this icon on a canvas using:

canvas.drawBitmap(myBitmap,X, Y, null);


i dont understand: you have drawable and want it to be drawn on the canvas, right?

if so, you dont need converting into Bitmap

just:

drawable.draw(canvas)

thanks
pskink
pskink
Master Developer
Master Developer
 
Posts: 719
Joined: Mon Nov 24, 2008 3:49 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google Feedfetcher and 12 guests