Image Resources

To create image resources, perform the following three steps:

  1. Create an XML-based .resx file containing the named resources.

  2. Convert the .resx file into a .resources file using Resgen.exe.

  3. Create a DLL, and embed the .resources file using the Assembly Generation Tool (AL).

    Note For more information on AL, see Appendix B: Resource Tools.

As with strings, if the image resources are localized into nondefault cultures, the process must be done for each culture — which must also be specified when using AL — as well as for a default, language-neutral culture.

The first step — creating the .resx file — is more complicated with image resources. There are several methods for doing this, but ultimately the resource must be converted into ASCII text using BASE64 encoding and embedded into an XML-formatted .resx file.

ResXGen — A handy tool for converting resources is the ResXGen utility included with this tutorial. This small console application takes three arguments: the name of the image file, the .resx output file, and the name to give the resource. The following command line is from the Build.bat file for the Graphic sample application:

ResXGen /i:un.jpg /o:Images.resx /n:flag

A more complete description of this tool, including a discussion of the source code, can be found in Appendix B: Resource Tools.

ResEditor — Another tool for converting resources is the ResEditor utility included with this tutorial. This Windows Forms application allows to you add and delete resources — including bitmaps, icons, and strings — that are located in .resources files. By using a Properties window, ResEditor allows you to explore the properties of graphic resources and directly edit string resources.

To illustrate how to use this tool (which might not be completely obvious), you can now walk through the process of creating a common .resources file that combines the German resources from the WorldCalc and Graphic samples discussed earlier. Start ResEditor, and open MyStrings.de.resources from the \de subdirectory of the WorldCalc sample directory for either Visual Basic or Visual C#. Note that the string name/value pairs are listed in the property window. In the Add group of controls near the bottom of ResEditor, type flag, and click the Add button (which will no longer be disabled). A new node is added to the tree of controls and properties that is on the left. Select the new flag node, and click the ellipsis button (...) that is just to the right. Navigate to the \flags subdirectory of the WorldDocs sample, and specify the de-DE.jpg image file. Note that the properties for the Flag bitmap are now shown as a thumbnail image — in this case, of the German bitmap. You should now see something like the following illustration.

A more complete description of this tool, including a discussion of the source code, can be found in Appendix B: Resource Tools.

See Also

Packaging Resources | Retrieving Resources Using Code | Resources Summary | Appendix A: Additional Resource Information | Appendix B: Resource Tools