How to read all icons in a .ico file

B

Bob Altman

Hi all,

If I have a .ico file that contains mulitple icons, is there a way to
construct System.Drawing.Icon objects from all of the images in the file?
The Icon constructor does not provide an "index" argument to specify which
icon to load into the Icon object.

Same question for .exe and .dll files: Icon.ExtractAssociatedIcon
presumably returns an Icon with a PE file's primary icon image (the
documentation is very sketchy). If my PE file contains multiple icon
resources, is there a way to enumerate them and extract the icons from them?

TIA - Bob
 
S

Steven Cheng[MSFT]

Hello Bob,

From your description, you're wantting to programmatically extract icon
images(multiple) from a .ico file (or some other win32 resource file like
exe or dll), right?

Based on my research, for such cases that we need to load win32 resources
from a certain resource image in .net framework code, the most common way
is manually parse the ico file based on its file structure. For exe and
dll, since there are existing win32 API to load and extract resource, you
can use PInvoke to call some unmanaged API in your .net code. I have found
the following two web articles which has provide some code on reading
multipe icons from ico and other resource image:

#Access multiple icons in a single icon file
http://www.codeproject.com/dotnet/MultiIcon.asp

#IconLib - Icons Unfolded (MultiIcon and Windows Vista supported)
http://www.codeproject.com/useritems/IconLib.asp

also, following is a project which originally created via VB and rewritten
in C#, it is also quite a good example for your reference:

#.NET Icon explorer
http://www.vbaccelerator.com/home/NET/Utilities/Icon_Extractor/IconExplorer.
asp

Hope this helps you.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Thanks for your reply Bob,

I'm glad the information helps you. Yes, the link to the Iconexplorer may
be broke due to line break. Anyway, you can easily get it by searching
".net icon explorer"

Have a nice day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top