views:

276

answers:

3

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.

A: 

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

moogs
Except for sizes above 48x48, it seems.
romkyns
A: 

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:

Eduardo Molteni
+1  A: 

Simple answer to all your questions: IconLib

arbiter
Thanks for this link. Looks like a great article. I don't need this any more, but next time I work with icons, I'll definitely check this library out. Hope your answer helps out others too. It's the best answer so far, so I've accepted it, though if a simpler answer comes along that doesn't require external libraries, I'd prefer that.
Drew Noakes