开发者

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

开发者 https://www.devze.com 2023-03-06 20:22 出处:网络
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?

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(...)开发者_如何学C, 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.


Simple answer to all your questions: IconLib


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号