how can I convert System.Drawing.Icon to System.Drawing.Image?
44,111
Solution 1
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
Solution 2
Could you use the ToBitmap()
method.
Solution 3
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.
Solution 4
Original at : Convert Icon to Image in C#
Icon a = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe");
Image im = a.ToBitmap()
Solution 5
Very simple. Icon has a method named ToBitmap
.
Image converted_image = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe").ToBitmap()
Author by
The Mask
Updated on July 09, 2022Comments
-
The Mask almost 2 years
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?
-
The Mask over 12 yearsI didn't knew that this
cast
it's possible. Thanks. -
John Faulkner almost 11 years+1 @TheMask - Thanks, I knew that a million years ago - saved me a bit of work toady!