49

I'm getting icon from another application using this:

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

how to convert it to System.Drawing.Image?

demonplus
  • 5,613
  • 12
  • 49
  • 68
The Mask
  • 17,007
  • 37
  • 111
  • 185

5 Answers5

87

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

dknaack
  • 60,192
  • 27
  • 155
  • 202
11

Could you use the ToBitmap() method.

ToBitmap()

Sam Greenhalgh
  • 5,952
  • 21
  • 37
6

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.

Zac
  • 4,510
  • 3
  • 36
  • 44
4

Original at : Convert Icon to Image in C#

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

Image im = a.ToBitmap()
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
3

Very simple. Icon has a method named ToBitmap.

Image converted_image = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe").ToBitmap()
DanielG
  • 131
  • 11