Selecting image in folder using MonoTouch

2019-09-14 22:32发布

问题:

I'm using monotouch and am having a brainfreeze. I'm trying to by code use an image that's in a folder.

The project structure:

Solution - Project -Images -picture.jpeg

The code:

UIImage image = UIImage.FromFile("\\Images\\picture.jpeg");

And I've also tried:

UIImage image = UIImage.FromFile("Images\\picture.jpeg");

The build action is set to content and I can use the picture without crashing if I just leave it in the root of the project. What's my problem?

Thanks

回答1:

Oh of course... iOS, paths go by / and not \....

Correct code: UIImage image = UIImage.FromFile("Images/picture.jpeg");

Told you it was a brainfreeze!