FrancineTaylor Posted May 16, 2011 Posted 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. Quote
Administrators PlausiblyDamp Posted May 17, 2011 Administrators Posted May 17, 2011 .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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
FrancineTaylor Posted May 17, 2011 Author Posted May 17, 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. Quote
Leaders snarfblam Posted May 17, 2011 Leaders Posted May 17, 2011 See http://msdn.microsoft.com/en-us/library/ms142127.aspx. Simply pass the stream and the desired size to the constructor. Quote [sIGPIC]e[/sIGPIC]
FrancineTaylor Posted May 18, 2011 Author Posted May 18, 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. Quote
Administrators PlausiblyDamp Posted May 18, 2011 Administrators Posted May 18, 2011 Did you look at the various constructor overloads (http://msdn.microsoft.com/en-us/library/system.drawing.icon.icon.aspx)? Using them you can specify which size to return, if you know it will have 3 or 4 sizes then simply ask for each in turn. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.