Thursday, September 10, 2009

Loading Image Resources

Here's sample code to load an image resource file, which works even if the resource file is not in the executable assembly, but in a referenced assembly.

Bitmap bmp = new Bitmap(

    System.Reflection.Assembly.GetAssembly(typeof(pick_a_class)).

    GetManifestResourceStream("Dll.Path.Image.jpg"));


pick_a_class is the name of any class in the relevant assembly.

The resource name may not be obvious. Here's code to determine the exact names of the various resources:

string[] all = System.Reflection.Assembly.GetAssembly(typeof(pick_a_class)).

    GetManifestResourceNames();

No comments: