Click here to Skip to main content
Licence CPOL
First Posted 17 Feb 2006
Views 33,536
Downloads 514
Bookmarked 12 times

Extract images from private ImageLists

By | 17 Feb 2006 | Article
Shows how to extract images from an ImageList on a form.

Sample Image - extractimages.jpg

Introduction

Sometimes you want to extract an image from an existing .NET DLL which is not included as a default resource. For instance, you added an image to an ImageList and forgot where the image came from. You now wish to save this image, which is impossible using the IDE of Visual Studio. To do this, I wrote this small piece of code, which is not completely foolproof, but should work in most occasions.

How it's done

First, I open the DLL and scan it for objects of type Form (exception handling removed):

Assembly ass = Assembly.LoadFrom(textBox1.Text);
Type[] types = ass.GetExportedTypes();
            
foreach(Type type in types)
{
    if (!type.IsAbstract && type .IsSubclassOf(typeof(Form)))
    {
        // create instance and extract images
        Form fm = (Form) ass.CreateInstance(type.FullName);
        extractImages(fm);
    }
}

Extracting the images is quite easy; just remember that there can be more than one ImageList. The same can be done to extract images from other types of controls. I convert the images to PNG to recreate the transparency.

Type t = form.GetType();
FieldInfo field = t.GetField("components", 
   BindingFlags.NonPublic | BindingFlags.Instance );
IContainer comps = (IContainer)field.GetValue(form);
int imglist_idx=0;
foreach(Component c in comps.Components)
{
    if (c is ImageList)
    {
               // .. save individual images

.... and so on, hope you get the idea.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Guido_d

Web Developer

Netherlands Netherlands

Member

I am a .NET developer from Gouda, the Netherlands, developing software since mid eighties.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General.Net 4 and form not expecting to be called without prerequisites Pinmembermbierman12:14 31 Aug '11  
Suggestionvery good PinmemberReniD23:29 21 Jul '11  
GeneralMy vote of 5 Pinmemberjswolf1921:01 5 Jul '11  
GeneralMy vote of 5 PinmemberLatif.Kankanwadi19:56 25 Mar '11  
Generalnice PinmemberPranay Rana0:04 30 Dec '10  
GeneralNice tool. Some suggestions. PinmemberDrew Noakes23:34 12 Jun '08  
GeneralI like!!!! Pinmemberchris1752:47 27 Nov '07  
GeneralRe: I like!!!! PinmemberSteve Hansen3:05 27 Nov '07  
QuestionCan this work on an exe? Pinmemberncarty972:52 11 Apr '07  
AnswerRe: Can this work on an exe? PinmemberGuido_d3:00 25 Sep '07  
GeneralRe: Can this work on an exe? PinmemberDrew Noakes23:27 12 Jun '08  
Generalcomments PinmemberPaul Brower2:08 17 Feb '06  
GeneralRe: comments PinmemberGuido_d2:36 17 Feb '06  
GeneralRe: comments PinmemberPaul Brower2:48 17 Feb '06  
GeneralRe: comments PinmemberGuido_d3:02 17 Feb '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 17 Feb 2006
Article Copyright 2006 by Guido_d
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid