Click here to Skip to main content
15,169,823 members
Articles / Programming Languages / C#
Posted 17 Feb 2006


13 bookmarked

Extract images from private ImageLists

Rate me:
Please Sign up or sign in to vote.
4.05/5 (10 votes)
17 Feb 2006CPOL
Shows how to extract images from an ImageList on a form.

Sample Image - extractimages.jpg


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);

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.


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


About the Author

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

Comments and Discussions

General.Net 4 and form not expecting to be called without prerequisites Pin
mbierman31-Aug-11 13:14
Membermbierman31-Aug-11 13:14 
Suggestionvery good Pin
ReniD22-Jul-11 0:29
MemberReniD22-Jul-11 0:29 
GeneralMy vote of 5 Pin
jswolf195-Jul-11 22:01
Memberjswolf195-Jul-11 22:01 
GeneralMy vote of 5 Pin
Latif.Kankanwadi25-Mar-11 20:56
MemberLatif.Kankanwadi25-Mar-11 20:56 
Generalnice Pin
Pranay Rana30-Dec-10 1:04
professionalPranay Rana30-Dec-10 1:04 
GeneralNice tool. Some suggestions. Pin
Drew Noakes13-Jun-08 0:34
MemberDrew Noakes13-Jun-08 0:34 
GeneralI like!!!! Pin
Christopher Stratmann27-Nov-07 3:47
MemberChristopher Stratmann27-Nov-07 3:47 
GeneralRe: I like!!!! Pin
Steve Hansen27-Nov-07 4:05
MemberSteve Hansen27-Nov-07 4:05 
QuestionCan this work on an exe? Pin
ncarty9711-Apr-07 3:52
Memberncarty9711-Apr-07 3:52 
AnswerRe: Can this work on an exe? Pin
Guido_d25-Sep-07 4:00
MemberGuido_d25-Sep-07 4:00 
GeneralRe: Can this work on an exe? Pin
Drew Noakes13-Jun-08 0:27
MemberDrew Noakes13-Jun-08 0:27 
Generalcomments Pin
Paul Brower17-Feb-06 3:08
MemberPaul Brower17-Feb-06 3:08 
I strongly recommend some error handling in this little utility ... I've tried about a dozen various dll's so far, and it bombed on all of them.

Also, recommending specific windows / ms office dll's that you have tested this on would also be helpful.

Assuming this does actually work, an enhancement suggestion would be to provide an option to "walk the subdirectories" of a specified path, and try to rip all the images out of any dll's.

GeneralRe: comments Pin
Guido_d17-Feb-06 3:36
MemberGuido_d17-Feb-06 3:36 
GeneralRe: comments Pin
Paul Brower17-Feb-06 3:48
MemberPaul Brower17-Feb-06 3:48 
GeneralRe: comments Pin
Guido_d17-Feb-06 4:02
MemberGuido_d17-Feb-06 4:02 

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

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