0

I'm having problem loading images to my project. I have the image in a folder named microassig this folder is on my desktop, this folder is to be sent online to my tutor, thats my line of code:

private Image imageOpen = Image.FromFile("\microassig\openOff.bmp");

I don't want to put the directory c:/ because is directory will be different from mine hence why i'm just using the ("\microassig\openOff.bmp");

The problem is that the image doesn't load.

Jonathan Eustace
  • 2,469
  • 12
  • 31
  • 54
h l
  • 1
  • You need to provide more details - is it a web application? a winforms application? what error are you getting? please note that you're escaping unwanted characters: add a `@` to `Image.FromFile(@"\microassig .....");` – Shai Aug 01 '12 at 12:49

3 Answers3

0

Locate your project's

bin\debug folder

You can do this by right-clicking on your project solution and clicking Open in Windows Explorer.

Store/Save the file as

openOff.bmp

Then you can just do:

private Image imageOpen = Image.FromFile("openOff.bmp");
Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
0

You should not be using the Image.FromFile. You need to add the image as a resource into the project. See this link: http://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.80).aspx

user989056
  • 1,275
  • 2
  • 15
  • 33
0

The \ doesn't imply your desktop. You should use GetFolderPath for that (See C# Get Special Folder) There are a few ways to go about this. You could add your image as a resource.

Or, more in the line of what you are already doing you could change your code to something like this:

private Image imageOpen = Image.FromFile("openOff.bmp");

Then move the openOff.bmp to your bin folder (where the exe is saved).

While you keep the openOff.bmp in the same folder as your executable it should find it.

Community
  • 1
  • 1
Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100