how can I convert System.Drawing.Icon to System.Drawing.Image?

Original at : Convert Icon to Image in C#

Icon a =  Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe");

Image im = a.ToBitmap()

For who wants to do the inverse: (VB.NET; myImage-> myIcon)

Dim tmpBmp As Bitmap
tmpBmp = myImage
Dim hIcon As IntPtr = tmpBmp.GetHicon
myIcon = Icon.FromHandle(hIcon)

I'm writing this here beacause by googling "System.Drawing.Image' converted to 'System.Drawing.Icon" brings here and I think it does not deserve a new question.


Description

The Bitmap is derived from Image so you can use Icon's .ToBitmap() method.

Sample

Icon IEIcon = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe");
Image im = IEIcon.ToBitmap();

More Information

  • MSDN - Bitmap Class
  • MSDN - Image Class

Could you use the ToBitmap() method.

ToBitmap()