Drew Noakes
Drew Noakes

Reputation: 310802

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

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.

Upvotes: 4

Views: 5598

Answers (3)

arbiter
arbiter

Reputation: 9575

Simple answer to all your questions: IconLib

Upvotes: 3

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

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:

Upvotes: 0

moogs
moogs

Reputation: 8202

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

Upvotes: 0

Related Questions