Convert Icon To Bitmap code snippit

Convert Icon To Bitmap code snippit:

This is just another little tip to show how easy it is to convert from an Icon to an Image.  For example, if you have an Icon and you want to show it in a PictureBox you have to convert it to a BitMap first.  This little Snippit will do it for you.

private Image ConvertIconToImage(Icon icon)
Bitmap b = new Bitmap(icon.Width, icon.Height,  
Graphics g = Graphics.FromImage(b);
g.FillRectangle(new SolidBrush(Color.Empty), new Rectangle(0, 0, b.Width, b.Height)) ;
g.DrawIcon(icon, 0, 0);
g.Dispose() ;
return b ;


About JohnHowell

I am a professional software developer with over 20 years of experience. I currently specialize in Microsoft technologies such as VS, TFS, C#, VB.Net, WCF, WPF, WW, etc.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s