Is there a way to do something like opening a file picker, choosing an image in the file system and loading it?
Texture2D has a FromStream(…) method. you have to be careful with it as the content manager doesn’t track it. Also you have to make sure it’s resources are disposed of when your done with it.
No picker if it were windows only and just a little tool. You could just add winforms as a reference and call to the winforms filedialog its kinda a pain and i wouldn’t depend on that for release. People have ui’s you can use though on this forum if you do a search and this in fact might work best if its just going to be on windows.
monogame win forms topic
127 posts on this one. UI Frameworks
Personally if i were to pick one id probably use Geon Bit Ui. GeonBit.UI: UI extension for MonoGame
I am right now determined to make my own that wont produce garbage is standalone monogame and does the stuff i want it to do which is ridiculous probably why im stuck and posting so much instead.
Untested, and would only work in Windows
#if WINDOWS
public static Texture2D LoadTextureFromFile()
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = "/";
openFileDialog.Filter = "PNG Image (*.png)|*.png";
openFileDialog.RestoreDirectory = true;
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == DialogResult.OK)
using (Texture2D loadedTexture = Texture2D.FromStream(graphicsDevice, openFileDialog.OpenFile()))
return loadedTexture;
}
return null;
}
#endif