|
-
December 29th, 2008, 02:21 PM
#1
pictures in the program
I use following line to get an image file.
Code:
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...
-
December 29th, 2008, 02:27 PM
#2
Re: pictures in the program
1) Embed the picture as a resource.
or
2) Change the path to a relative one
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 29th, 2008, 02:42 PM
#3
Re: pictures in the program
How about this
Code:
System.IO.Path.GetFullPath(path)
??
-
December 29th, 2008, 03:54 PM
#4
Re: pictures in the program
use the app.config to hold a file path to the image directory
-
December 29th, 2008, 04:48 PM
#5
Re: pictures in the program
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.
Code:
string exeLocation = Assembly.GetExecutingAssembly().Location;
string exeDir = Path.GetDirectoryName(exeLocation);
string imageDir = Path.Combine(exeDir, "images");
string imageLocation = Path.Combine(imageDir, "mypic.png");
-
December 30th, 2008, 02:52 AM
#6
Re: pictures in the program
it is easier to do this:
Code:
pictureBox1.Image = System.Drawing.Image.FromFile("images/test.jpg");
images folder should be in the same folder that your exe file resides.
Please rate my post if it was helpful for you.  Java, C#, C++, PHP, ASP.NET
SQL Server, MySQL
DirectX
MATH Touraj Ebrahimi
[toraj_e] [at] [yahoo] [dot] [com]
-
December 30th, 2008, 07:21 AM
#7
Re: pictures in the program
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.
-
December 30th, 2008, 07:34 AM
#8
Re: pictures in the program
 Originally Posted by MadHatter
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
-
December 30th, 2008, 08:27 AM
#9
Re: pictures in the program
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|