50

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?

5 Answers 5

88

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

2
  • I didn't knew that this cast it's possible. Thanks.
    – The Mask
    Jan 19, 2012 at 18:05
  • +1 @TheMask - Thanks, I knew that a million years ago - saved me a bit of work toady! Jul 9, 2013 at 2:22
11

Could you use the ToBitmap() method.

ToBitmap()

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.

4

Original at : Convert Icon to Image in C#

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

Image im = a.ToBitmap()
3

Very simple. Icon has a method named ToBitmap.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.