TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

Embedding an Image Into Your Assembly

How to embed an image resource into an assembly and then use the embedded resource:

  1. Add the image to your project in the VS.NET IDE.
  2. Select the image in the Solution Explorer and then set the "Build Action" property (in the Properties Window) to "Embedded Resource"
  3. To access the image via code, use something similar to the following:

private void button1_Click(object sender, System.EventArgs e) {
    System.Reflection.Assembly assem = System.Reflection.Assembly.GetExecutingAssembly();
    string
resName = assem.GetName().Name.ToString() + "." + "test.JPG";
    System.IO.Stream imageStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resName);
    Image img = Image.FromStream(imageStream);
    this
.pictureBox1.Image = img;
}


Digg!

posted on Wednesday, October 27, 2004 11:15 AM

Feedback

No comments posted yet.