/Resource-Reflector

.NET Resource Reflector

Primary LanguageC#GNU Lesser General Public License v3.0LGPL-3.0

Resource-Reflector

A .NET application written in C# for viewing and extracting assembly resources.

Sample image

This article examines a simple utility application, Resource Reflector, which allows you to view, save, and copy images, icons, and cursors embedded in an assembly. The utility was compiled against v2.0 of the .NET framework, but the core functionality could easily be ported to v1.x, if necessary.

Background

Before looking at how Resource Reflector works, let's take a moment to review what an embedded resource is. When an assembly is created, it is possible to store arbitrary files within it, such as BMPs, XML files, etc. Those files are called embedded resources. Embedding a resource within an assembly has several benefits, such as:

Simplifying deployment (less files to manage). Simplifying resource consumption (there is no chance that the file will be missing at runtime). You can easily embed an image into an assembly using Visual Studio .NET, by following these steps:

Add an image file to a project. In Solution Explorer, right click on the image file and select Properties from the context menu. In the Properties window, select Embedded Resource for the Build Action property. Compile the project into an assembly. As you might imagine, the .NET framework provides support for programmatic retrieval of embedded resources. We will be examining how that is implemented, later in the article.

Using the utility

There are four essential steps to using this tool:

  1. Run Resource Reflector.exe
  2. Click the Open button to locate the assembly which contains the image(s) you want to extract.
  3. Navigate to the image(s) you are interested in, via the BindingNavigator at the top of the window.
  4. Click either the Save or Copy button to persist an image to the disk or clipboard.
* Tip - Steps 1 and 2 can be consolidated by simply drag-dropping the target assembly onto Resource Reflector.exe.

Other features

  • Save Options
  • When saving an embedded icon or cursor, you have the option of saving it either as the original type of file or as a bitmap. The Save As dialog will default to using the extension which corresponds to the original type of the embedded resource.
  • Open via Drag-Drop
  • In addition to being able to open the application with an assembly loaded by drag-dropping the assembly onto Resource Reflector.exe, you can also load an assembly while the app is running, via drag-drop. Simply drop an assembly onto the form, and the embedded images it contains will be loaded.
  • 'All Images' tab
  • Provides a grid view of every image in the assembly. It makes searching for an image faster.
  • Properties View
  • A PropertyGrid which displays detailed information about the current image. Click the rightmost button on the toolbar to show/hide this view.
  • Context Menu
  • Provides quick access to save, copy, or show/hide properties of an image.
  • View Options
  • When the 'Individual Image' tab is selected, the toolbar will have a combobox which allows you to alter the way that the current image is rendered (such as zoomed, centered, etc.).

References

John Smith, 3 Apr 2006 - Extracting Embedded Images From An Assembly

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007