How can I extract multiple sized images from an .ICO embedded on a .resources file?

FrancineTaylor

Newcomer
Joined
May 16, 2011
I have a file, "multi.ico" which has four images of different sizes (16x16, 24x24, 32x32, 48x48). Each sized image is a different color, to make it easy to tell which size we are dealing with. This file has been inserted into a resource file "Multi.resources" using Lutz Roeder's .NET Resourcer.

I need to be able to extract the ico from the .resource file in such a way as to keep all four sizes of images. Ideally, I would like to have a wrapper class around the .ico object which allows selection of the image of the proper size.

I have a working wrapper that I can use with a standalone .ico file (multi.ico), but my company system has a lot of images, and we need to be able to bundle them into .resource files for distribution.

Can anybody show me a piece of code which would take a.resources and extract the 16x16 version of a contained .ico file. I can't seem to get at anything but the 32x32 sized image.
 

PlausiblyDamp

Administrator
Joined
Sep 4, 2002
Location
Lancashire, UK
.Net's Icon class can probably do what you are after. If you look at the various constructors an Icon can be created from a resource stream and you can also specify your desired size - if the icon contains multiple resolutions then it will pick one based on your requested size.
 

FrancineTaylor

Newcomer
Joined
May 16, 2011
Can you give me an example? Bearing in mind that what I am working with is a standalone .resource file, and that the resource file contains multiple .ico files. The stream needs to be opened at the beginning of the correct icon.
 

FrancineTaylor

Newcomer
Joined
May 16, 2011
This code works fine if the icon comes from a single image .bmp, .ico, .png file, but if the file contained in the .resource file is a multi-image .ico (a single .ico with multiple images of different sizes inside) you end up with just one of those sizes. In a file with 16x16, 24x24, 32x32 and 48x48, the image I get in the Icon is always the 32x32 image. No matter what sort of size adjustments you do on the Icon or how you manipulate it, the image doesn't change. It is always the 32x32, just resized.
 
Top Bottom