C# .NET - Images folder in my project/solution

Asked By A M on 02-Feb-06 11:07 AM
Working with Visual Studio...I created a new solution and created a new project (inside the solution).  My project makes use of several images, which I would like to gather in a common folder.  

How do I go about accessing (referencing to) these images once they are in the folder inside the project/solution?  

What path should I use for loading the images onto the project forms?

Thanks

Relative Path - Asked By F Cali on 02-Feb-06 11:09 AM

You can use the relative path to access the images in your project.  For example, let's say you created a folder in your project called "images", to access files from this folder, simply use "images/Image1.jpg".

just give - Asked By Venkat K on 02-Feb-06 11:25 AM

the path as below, to access the images as
../images/yourimage.* if the images is in root directory

thanks, but - Asked By A M on 03-Feb-06 03:38 AM

Thanks for your reply.  However, it did not work for me.  I am using the System.Drawing method Bitmap().

Bitmap mybitmap = new Bitmap(Assembly.GetExecutingAssembly().GetTypes()[0], "images/Image1.bmp"); 

This is throwing a "Resource 'images/Image1.bmp' could not be found in class ...".
MSDN Example - Asked By F Cali on 03-Feb-06 11:18 AM
Here's an example from MSDN:

// Replace "filename" below with the actual filename for the JPG
//   file you added as a resource; the name is case-sensitive.
// Also make sure that "WindowsApplication1" is replaced with the
//   name of your project, if different.
Stream s = this.GetType().Assembly.GetManifestResourceStream("WindowsApplication1.filename.jpg");
Bitmap bmp = new Bitmap( s );
s.Close();
Graphics g = CreateGraphics();
g.DrawImage( bmp, 0, 0 );
bmp.Dispose();
g.Dispose(); 


Before doing this, follow these steps:

Add a Resource
1.  On the View menu, click Solution Explorer, and then select the new project that you created earlier. 

2.  On the Project menu, click Add Existing Item. 

3.  Locate and open one raster file (.jpg, .png, or .tif) and one metafile file (.wmf or .emf), and then follow these steps for each file: 

a.  In Solution Explorer, select the file, and then on the View menu, click Properties Window. 
b.  Set the Build Action to Embedded Resource. 
c.  On the Project menu, click Add Existing Item.