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,  
System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
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 ;
}

Unknown's avatar

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 comment