Unboxed Solutions Blog The frenetic soapbox

Oct 27

Sean

Embedding an Image Into Your Assembly

  • Created: Wednesday, October 27, 2004
  • Sean

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;
}

;