I'm trying to change a Drawn rectangle's image
spriteBatch.Draw(screenTexture, screen, background);
Where I reassign the screenTexture based on the image the user selected.
(I do this in update before the first call of draw)
screenTexture = Content.Load<Texture2D>(fileLocation);
However after the file is selected and it gets to the above code it is unable to open the filepath of fileLocation.
Unless there is an easier way I'm trying to solve this by creating a resource with the fileLocation after the user selects it.
I've read something about content pipeline needing to be used and I'm getting lost. Thread code used:
//Thread Method
Thread newThread = new Thread(new ThreadStart(ThreadMethod));
newThread.SetApartmentState(ApartmentState.STA);
newThread.Start();
public void ThreadMethod()
{
OpenFileDialog fileDialog = new OpenFileDialog();
DialogResult result;
result = fileDialog.ShowDialog();
if (result == DialogResult.OK)
{
fileLocation = fileDialog.FileName;
}
}
Answer: Although Sloppy(if someone doesn't mine showing me a cleaner version) This is what gave me the result I wanted.
FileStream fileStream = new FileStream(@fileLocation, FileMode.Open, FileAccess.Read);
Texture2D myTexture = Texture2D.FromStream(screenTexture.GraphicsDevice, fileStream);
screenTexture = myTexture;