Extract Images from Resx file

March 23, 2012


This article is not in the new development issues, but an old school issue.

I started an year ago to migrate most of my application from  Windows Forms to WPF platform. it was good most of the images also

transferred to anew and sexy look.

BUT, than tow weeks ago I found old window that I needed to migrate and there was not problem with the images, but that in the past

we used the ImageList structure and as you know the image stored the image data imbedded in the Control Resx file


So I had two options :

  • Mess my code and after the “InitializeComponent()” run over the images and save them. No Way !!!
  • Create external tool to extract those images for me.


This nice thing is that my creating this tool I remembered that there are images that also imbedded in the project but not as part of the ImageList

So, there for you an easy way to get your resources.



It’s Quite simple we load the Resx file to ResXResourceReader enumerate it and extract the images.

   1: ResXResourceReader reader = new ResXResourceReader(currentResxFile);

   2:                    var enumerator = reader.GetEnumerator();

   3:                    while (enumerator.MoveNext())

   4:                    {

   5:                        ...

   6:                    }

Still to extract the data from ImageList we’ll need to create an instant of it, populate the that (stream data) into the ImageStream after it run over

the imbedded images.


   1: ImageListStreamer ils = value as ImageListStreamer;

   2:                        if (ils != null)

   3:                        {

   4:                            ImageList imageList1 = new ImageList();

   5:                            imageList1.ImageStream = ils;

   6:                            if (imageList1 != null && imageList1.Images != null && imageList1.Images.Count > 0)

   7:                            {

   8:                                for (int i = 0; i < imageList1.Images.Count; i++, imageIndex++)

   9:                                {

  10:                                     ...

  11:                                }...

To save the images we’ll use the build-in function Image.Save to do so

We only need to decide the image extension, for that we use the Image.RawFormat

   1: private static string GetExtension(ImageFormat imageFormat)

   2:         {

   3:             if (ImageFormat.Bmp.Guid == imageFormat.Guid)

   4:                 return ".bmp";

   5:             if (ImageFormat.Emf.Guid == imageFormat.Guid)

   6:                 return ".emf";

   7:             if (ImageFormat.Exif.Guid == imageFormat.Guid)

   8:                 return ".exif";

   9:             if (ImageFormat.Gif.Guid == imageFormat.Guid)

  10:                 return ".gif";

  11:             if (ImageFormat.Icon.Guid == imageFormat.Guid)

  12:                 return ".ico";

  13:             if (ImageFormat.Jpeg.Guid == imageFormat.Guid)

  14:                 return ".jpeg";

  15:             if (ImageFormat.MemoryBmp.Guid == imageFormat.Guid)

  16:                 return ".bmp";

  17:             if (ImageFormat.Png.Guid == imageFormat.Guid)

  18:                 return ".png";

  19:             if (ImageFormat.Tiff.Guid == imageFormat.Guid)

  20:                 return ".tiff";

  21:             if (ImageFormat.Wmf.Guid == imageFormat.Guid)

  22:                 return ".wmf";

  23:             return ".bmp";

  24:         }

So, hope it’s helped you

You can download the source code from here.

Or Executable from here.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



  1. seoOctober 23, 2012 ב 22:12

    Very good day! may u pls assist me to to get a ym detector scanner? Anyone applied this acct and can detector scanner find in the event the online hackers additionally looking at this wife’s spy cams when all of us are chatting? cheers!

  2. shopDecember 26, 2012 ב 02:39

    The leading source for trustworthy and timely health and medical news and info.
    shop http://d.hatena.ne.jp/louisvuittonaaa/20121218/1355804927

  3. DominikSeptember 27, 2013 ב 03:10

    Thanks for your code. Helped me a lot. The only thing is that you are not incrementing imageIndex when extracting images or icons. So only a single Image_0000.png exists in output folder.