-
image.fromfile query
I have been using the image.fromfile to set images to a text box but I always have to use a full file path. Like here;
Code:
PictureBox1.Image = Image.FromFile("G:\VB.NET\Application1\Resources\Image1.jpg")
PictureBox2.Image = Image.FromFile("G:\VB.NET\Application1\Resources\Image2.jpg")
However if I install the application on another computer then surely this won't work as it needs a path relative to where it is installed. I tried "\Resources\Image1.jpg" but this doesn't seem to work. I need to find away so it works on all computers. I don't know if it changes this when the application is published but I don't have access to a second computer to test it. Any one know how to do it?
-
Re: image.fromfile query
There are numerous ways, but the simple one is to use Application.StartupPath and combine it with IO.Path.Combine.
-
Re: image.fromfile query
I have tried this but it keeps bringing up an error 'FileNotFoundException was unhandled' this is my code. The file defiantly exists, as it works on my computer like above.
Code:
Dim StartPath, pic1, f1 As String
StartPath = Application.StartupPath
pic1 = "Resources\Image1.jpg"
f1 = Path.Combine(StartPath, pic1)
Main.PictureBox1.Image = Image.FromFile(f1)
-
Re: image.fromfile query
Whenever you encounter "file not found" exception, always messagebox the file path to inspect it. In your case, I strongly beleive that you didn't copy the "Resources" folder to the "bin" directory of your project.
When you debug run your application, it runs from the "bin" folder of your project and thus application.startuppath returns the path to the "bin" folder.