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

▼魔方 西西 提交于 2019-12-03 01:02:35

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

Could you use the ToBitmap() method.

ToBitmap()

Original at : Convert Icon to Image in C#

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

Image im = a.ToBitmap()

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.

Very simple. Icon has a method named ToBitmap.

Image converted_image = Icon.ExtractAssociatedIcon(@"C:\Program Files\Internet Explorer\iexplore.exe").ToBitmap()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!