Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to "store" images in the exe / resources 1

Status
Not open for further replies.

tomcoombs

Programmer
Aug 14, 2003
65
GB
Hi All,

I can a : "picturebox.Image = Image.FromFile("c:\tom.bmp");"

But I do not want to be tied to using one directory!

When adding an image to a picturebox at design time the IDE does something fancy :

"this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));"



How do I put images into this "rescourse" beasty?

Thanks in advance.
Tom
 
Add the image file to the project using "Add an Existing Item". Set the "Build Action" property to "Embeded Resource". Then to create an Image object from it at runtime:
Code:
Image img = new Bitmap( Assembly.GetExecutingAssembly().GetManifestResourceStream("MyApp.myimage.jpg"));
Now do whatever you want with the image.

NOTE: The string resource is case sensitive and your projects properties "Assembly Name" and "Default Namespace" must be identical( MyApp in the example).

-pete
 
Hi Again

I got an error :-(

C:\GeevsTestApp\UserControl1.cs(193): The type or namespace name 'Assembly' could not be found (are you missing a using directive or an assembly reference?)

Thanks

Tom
 
Pete,

Did do, did find it. Was a little trigger happy on the reply.


Thanks again for your help.



Works a treat.
 
Pete,

Did do, did find it. Was a little trigger happy on the reply.


Thanks again for your help.



Works a treat.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top