Click to See Complete Forum and Search --> : pictures in the program


zorspas
December 29th, 2008, 01:21 PM
I use following line to get an image file.


pictureBox2.Image = System.Drawing.Image.FromFile("C:\\...")


But when I try to use the program on another computer, I have to change the path of the picture?

Can anyone, please, offer another way to acquire image files?

Many Thanks...

TheCPUWizard
December 29th, 2008, 01:27 PM
1) Embed the picture as a resource.
or
2) Change the path to a relative one

zorspas
December 29th, 2008, 01:42 PM
How about this


System.IO.Path.GetFullPath(path)


??

eclipsed4utoo
December 29th, 2008, 02:54 PM
use the app.config to hold a file path to the image directory

MadHatter
December 29th, 2008, 03:48 PM
if you don't embed the image (which is what I'd suggest you do. vs 2005+ has a resource editor that makes doing this a brainless operation), then you can include an image folder relative to the exe folder.

string exeLocation = Assembly.GetExecutingAssembly().Location;
string exeDir = Path.GetDirectoryName(exeLocation);
string imageDir = Path.Combine(exeDir, "images");
string imageLocation = Path.Combine(imageDir, "mypic.png");

toraj58
December 30th, 2008, 01:52 AM
it is easier to do this:


pictureBox1.Image = System.Drawing.Image.FromFile("images/test.jpg");


images folder should be in the same folder that your exe file resides.

MadHatter
December 30th, 2008, 06:21 AM
If I recall correctly (and I could be wrong), if you specify a path like that, it will use the working directory which isn't always the same as the executable path.

dannystommen
December 30th, 2008, 06:34 AM
If I recall correctly (and I could be wrong), if you specify a path like that, it will use the working directory which isn't always the same as the executable path.

That's correct, you are not wrong

ali_bilal_yousaf
December 30th, 2008, 07:27 AM
You may also place the picture in the same folder as the exe & use this

string picPath = Application.StartupPath + "\\Pic.jpg"

Kind Regards,
Ali Bilal Yousaf