how can I convert System.Drawing.Icon to System.Drawing.Image?

痞子三分冷 提交于 2019-12-20 11:48:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!