Using .resx Files to cache image files
Introduction
The .resx Files of the .NET Framework provide a very efficient method to provide Images to .NET applications. The SmartComponent Library provides tooling to build .resx Files from existing .png Files as well as API's to use those files at runtime instead of the individual .png Files.
Creating .resx Files from existing .png Files
The procedure Consultingwerk/Windows/Util/ImageCache/cache-images.p is capable of adding all Image files found in a directory and sub-directories to a new .resx File. The procedure is designed to be executed from an ANT Script and the PCTRun task. The ANT script in Consultingwerk/Windows/Util/ImageCache/build.xml is an example for how this procedure can be used. The ANT file cna be invoked like this
ant cache-images -f Consultingwerk\Windows\Util\ImageCache\build.xml -Dfilename=Consultingwerk\Windows\Images\images.resx
The ANT file supports 2 parameters:
Parameter Name | Description |
---|---|
-Dfilename | The name of output file (.resx File) |
-Ddirectory | The base directory in which to scan for images |
Initializing the IImageCache Service
The IImageCache Service is used by the Consultingwerk.Util.ImageHelper:Load method to return Images to the application. The ImageHelper:Load is the default routine of the SmartComponent Library framework to load images.
The Consultingwerk.Windows.Util.ImageCache Service is the default implementation of the IImageCache Service.
It's loaded from the Consultingwerk/Windows/Framework/Reference/services.xml or a custom service.xml file.
The service loads the .resx Files based on the IConfigurationProvider properties:
"LoadImageResources": "Consultingwerk/Windows/images.resx"
or
"LoadImageResources": { "1": "Consultingwerk/Windows/images.resx", "2": "Consultingwerk/Windows/another file.resx" }
The service will load .resx Files specified with the index 0 to 100.
Retrieving Images from the IImageCache Service
The ImageHelper:Load method will handle loading Images from the IImageCache Service when Registered with the ServiceContainer. Images are expected to be referenced by the relative file name.