C# 如何将 System.Drawing.Icon 转换为 System.Drawing.Image?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8930870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can I convert System.Drawing.Icon to System.Drawing.Image?
提问by The Mask
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?
如何将其转换为System.Drawing.Image?
采纳答案by dknaack
Description
描述
The Bitmapis derived from Imageso you can use Icon's .ToBitmap()method.
该Bitmap源自Image这样你就可以使用图标的.ToBitmap()方法。
Sample
样本
Icon IEIcon = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe");
Image im = IEIcon.ToBitmap();
More Information
更多信息
回答by Sam Greenhalgh
回答by Pranay Rana
Original at : Convert Icon to Image in C#
原文在:在 C# 中将图标转换为图像
Icon a = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe");
Image im = a.ToBitmap()
回答by DanielG
Very simple. Icon has a method named ToBitmap.
很简单。Icon 有一个名为 的方法ToBitmap。
Image converted_image = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe").ToBitmap()
回答by Zac
For who wants to do the inverse: (VB.NET; myImage-> myIcon)
对于谁想要做相反的事情:(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.
我在这里写这个是因为通过谷歌搜索“ System.Drawing.Image”转换为“System.Drawing.Icon”带来这里,我认为它不值得一个新问题。

