8

I have a path problem with UIImage.FromFile() method. My solution folder has 3 projects and the main UI project has an Images folder in it. I put all my project images in this folder and I have code like this:

UIImage myImg = UIImage.FromFile("Images/someImage.png");

I have already examined this and all these topics..

I set images property of build to "content" and etc..

Can you help me:

  • step by step adding an image to a specific project folder and use it dynamically
  • how to use NSBundle and why we have to use this?
Community
  • 1
  • 1
DortGen
  • 402
  • 2
  • 8
  • 22

2 Answers2

12

Generally, if you have right clicked on the file, gone to it's properties and marked it as Content then the following will work:

UIImage myImg = UIImage.FromFile(@"Images/someImage.png");
Ryan
  • 26,884
  • 9
  • 56
  • 83
  • Hello Mr.Ryan, thanks for your reply. I try this but when i select image file as Content, the i-phone simulator freezing. And worst, it never responses again if i change compile type of image whatever. when i google this situation, advises are "check your ios version". can you help? why simulator crashes when i change image compile type? – DortGen Jun 03 '11 at 09:27
  • 1
    I dont know - I have never seen that kind of behaviour. Are you sure the freezing is as a result of the image load operation and not another part of the code? – Ryan Jun 03 '11 at 10:59
  • I checked multiple times and i determine that is the situation. But i'll try again at this evening, i'll create an empty project and will add only images directory and try to use your code snipped. I'll write the result here again. – DortGen Jun 03 '11 at 13:15
  • Hello, i was created a new project and add an image and select it as content and write necessarily code and it runs perfect.. The problem is not at path, is in my main project. when i select build type Content in my real project the simulator fails and unless i check it back to "Nothing" and Clean Project it's not running again. – DortGen Jun 04 '11 at 10:46
  • 4
    I'm soo sorry, it was completely my mistake.. I was named the images folder with "Resources" and i didnt know this is a special name. When i rename it to anything else everything works fine.. – DortGen Jun 05 '11 at 21:22
  • No worries - at least you found the problem and restored your sanity! – Ryan Jun 06 '11 at 04:01
  • 2
    I just ran into the non-obvious `Resources` problem too. You learn something new every day, if you are lucky. – andynormancx Jun 21 '11 at 14:19
2

The very first question you linked to has the solution - you need to use Unix style paths ("/"), not DOS/Windows paths ("\").

You should also carefully check the casing of your paths - the emulator is more forgiving of incorrect case than the actual device is.

Finally, look inside of your .app bundle to verify that the image files are really where you think they are, relative to the root of the bundle.

Community
  • 1
  • 1
Jason
  • 86,222
  • 15
  • 131
  • 146