问题
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?
回答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
- MSDN - Bitmap Class
- MSDN - Image Class
回答2:
Could you use the ToBitmap()
method.
ToBitmap()
回答3:
Original at : Convert Icon to Image in C#
Icon a = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe");
Image im = a.ToBitmap()
回答4:
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.
回答5:
Very simple. Icon has a method named ToBitmap
.
Image converted_image = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe").ToBitmap()
来源:https://stackoverflow.com/questions/8930870/how-can-i-convert-system-drawing-icon-to-system-drawing-image