Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load image from folder in solution?

Tags:

c#

I'm trying to load an image from a folder in the solution, but I only get a error message that it's not found. What have I done wrong? The code below is in the MainForm.cs that is at the same level as the Resource folder. Help is preciated! Thanks!

 // Images
 Image imageCircle = Image.FromFile("Resources/circle.png");

 // Set deafult picture on start
 pictureBox1.Image = imageCircle;
like image 943
3D-kreativ Avatar asked May 20 '12 13:05

3D-kreativ


2 Answers

Edit: Fixed Broken Links

Take a look at this MSDN article, it discusses Adding and Editing Resources and what your options are, and this MSDN article discussing Linked and Embedded resources using the Resource Designer.

Project Properties Resources

Then select your file

enter image description here

Then you can access it like Madurika suggests.

i.e.

Image imageCircle = YourPojectName.Properties.Resources.YourFileNameHere;

enter image description here

like image 81
Mark Hall Avatar answered Nov 17 '22 10:11

Mark Hall


It always take the path from the where executable is located(bin folder). So if you can access it using full path, problem will solved. Or you can have a configuration item for the root folder. then access like Image.FromFile(rootFolder+ "Resources/circle.png");. Anyway this issue wont be there when you deploy it.

And if you are using resource file,

<projectName>.Properties.Resources.<ImageName>;

will return the image.

like image 7
Madurika Welivita Avatar answered Nov 17 '22 09:11

Madurika Welivita