Unboxed Solutions Blog The frenetic soapbox
Embedding an Image Into Your Assembly
How to embed an image resource into an assembly and then use the embedded resource:
- Add the image to your project in the VS.NET IDE.
- Select the image in the Solution Explorer and then set the "Build Action" property (in the Properties Window) to "Embedded Resource"
- 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;
}



