Finding image file path inside monomac project

I'm new to mono and monomac, and I'm stuck with something that I hope is very easy to fix.

In my application, I want to change some images at runtime, so I created the Images folder with my photos inside the project root. But when I try to change the image in my code, the image cannot be found, so I think I'm writing the wrong path.

I am trying to get the image as follows:

NSImage image = new NSImage("Images/image2.jpg"); // I tried with different paths but nothing changed...
pic1.Image = image;

If I use the full path to the image, everything works fine, but I need to use relative. How should I get the correct relative path?

I am using Monodevelop.

Thank.

+3
source share
3 answers

MonoMac Github, , .

:

var myImage = NSImage.ImageNamed ("some.png");

"/Images", .

, .

+1

You also use System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly (). Location) to get the path to the resources.

0
source

All Articles