How can I extract a specific Image from an Icon file in .NET?

江枫思渺然 提交于 2019-12-04 04:05:30

问题


Icon files (*.ico) may contain multiple images at different sizes and of different colour depths.

How can I obtain a System.Drawing.Image object from a .ico file?

One option is Image.FromFile(...), but for icon files with multiple images there is no way to specify which image size and colour depth to return.

Ideally the solution would use only managed code, but I'm happy to hear about interop calls to Win32 functions as well.


回答1:


Simple answer to all your questions: IconLib




回答2:


System.Drawing.Icon can load a specified size from a file. I don't know about depth, though. http://msdn.microsoft.com/en-us/library/ms142130.aspx




回答3:


You will need to use

Dim icon As System.Drawing.Icon
icon = icon.FromHandle(hIcon)

In the hIcon structure you can specify the color depth

This links will guide you in the right direction:

  • http://www.geekpedia.com/tutorial219_Extracting-Icons-from-Files.html
  • http://bytes.com/groups/net/120863-system-drawing-icon-hicon-ptr-iconimage-structure


来源:https://stackoverflow.com/questions/510717/how-can-i-extract-a-specific-image-from-an-icon-file-in-net

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