There's a few things you need to understand to get this to work.
First, what you're trying to do will be platform specific. So I'm going to assume you're only concerned with getting it working on Windows.
Second, if you're adding content to the
Content.mgcb file it will be compiled by MonoGame's Content Pipeline and it will end up in a
Content folder as an XNB file relative to the executable.
For example, let's say you've added a
texture.png file to your
Content.mgcb file. When the game or tool runs the image will be compiled and end up in the following place by default.
This means that the path relative to your executable would be
Content\texture.xnb and you could use the regular C# method
Path.GetFullPath("Content\texture.xnb") to get the full path relative to the executable.
Of course, you won't be able to load an XNB file with
Image.FromFile(string fileName) because it's not a standard image format. To deal with that what you'll probably want to do is copy the original
texture.png file to the output folder.
To do that you can use the Properties of the file and set the Build Action to Content and the Copy to Output Directory to Copy if newer.
texture.png file will be available to load relative to the executable.
Lastly, if you want to actually load this PNG file directly into MonoGame without using the
Content.Load method you can write you're own method using
Texture2D.FromStream like this:
public Texture2D LoadTexture(string filePath)
using (var fileStream = File.OpenRead(filePath))
var newTexture = Texture2D.FromStream(GraphicsDevice, fileStream);
private static void PremultiplyTexture(Texture2D texture)
var data = new Color[texture.Width * texture.Height];
for (var i = 0; i < data.Length; i++)
data[i] = Color.FromNonPremultiplied(data[i].R, data[i].G, data[i].B, data[i].A);
Note: I've also included a method to pre-multiply the texture because this is something normally done by the MonoGame Content Pipeline. If you don't do this the texture won't work properly with