Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MonoTouch - How to specify image path of UIImage.FromFile()

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?
like image 800
DortGen Avatar asked Jun 01 '11 19:06

DortGen


2 Answers

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");
like image 126
Ryan Avatar answered Nov 12 '22 22:11

Ryan


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.

like image 24
Jason Avatar answered Nov 12 '22 22:11

Jason