Monday, November 07, 2005

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 ;


Post a Comment

<< Home