Click here to Skip to main content
15,884,388 members
Articles / Programming Languages / Perl
Tip/Trick

Extracting Images from a RESX File

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
6 Jul 2017CPOL1 min read 9.4K   277   3  
A simple way of extracting all images from a RESX file using a simple perl script

Introduction

This script provides a simple way of extracting all the images from a RESX file (used by C# and VB) to store resources used in forms.

Background

I created this script because I was looking for a quick way of extracting all the images from a VB project I was converting to C++. I found utilities that allow for extracting single images, but nothing quick and easy that would do it all in one go.

A bit of research told me that the files were using base64 encoding so it was fairly easy to create a script using perl features like:

PERL
use MIME::Base64

to import the functions I needed to do the conversion. After that, I just needed to scan for the right resources and output each one to a folder using the name of the resource as a base filename.

Using the Code

The script is very easy to use. All you need to do is provide it an input file and an optional output file in the following manner:

PERL
perl --to outputfolder inputfile

The script itself is very simple and relies on simple text pattern matching to find the resources and in its current form only extracts Bitmap (BMP) and Icon (ICO) files, but should be easily extended by modifying this section:

PERL
if ($type =~ /^System.Drawing.Bitmap, System.Drawing/)
    {
    $filename = "$outputfolder/$name.bmp";
    }
elsif ($type =~ /^System.Drawing.Icon, System.Drawing/)
    {
    $filename = "$outputfolder/$name.ico";
    }

to match the resource of interest.

History

  • 6th July, 2017: Initial version

License

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


Written By
Software Developer (Senior) SwiftTec Ltd
United Kingdom United Kingdom
I am a Senior Software Developer specialising in C++ cross-platform development but with a wide variety of experience spanning languages such as C, C++, C#, VB, Java, Javascript, PHP and perl. I run my own software development company, SwiftTec Ltd which focuses on affordable software products such as our membership system, and specialist software for lighting and song management. I also work full time for another company (PALSupport UK Ltd) writing cross-platform code for recording and replaying data

Comments and Discussions

 
-- There are no messages in this forum --