I am having a really hard time with saving a screenshot in MonoGame. Every time I save the screen shot it comes out all messed up, kind of like how the premium channels used to look if you didn't subscribe to them. Like messing with the tracking on a VHS tape. I have now idea what is going on. I created a completely new project just to see if it was my project or if it was MonoGame. It worked perfectly with the new project. I know that no one can know what exactly I am doing wrong, but can anyone even suggest to me why something like this might happen? Should I be looking into my camera class? Or maybe something about the saving of the file is getting messed up? I'm at a loss, and I have a game due to Microsoft today, and I have obviously already missed that deadline. The following is my save screenshot method:
async void ScreenShot()
{
RenderTarget2D renderTarget = new RenderTarget2D(
_graphics.GraphicsDevice,
_graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
_graphics.GraphicsDevice.PresentationParameters.BackBufferHeight);
_graphics.GraphicsDevice.SetRenderTarget(renderTarget);
Draw(new GameTime());
_graphics.GraphicsDevice.SetRenderTarget(null);
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
Stream stream = null;
if (storageFolder != null) stream = await storageFolder.OpenStreamForWriteAsync("testing.jpg", CreationCollisionOption.ReplaceExisting);
if (stream != null)
{
renderTarget.SaveAsJpeg(stream, renderTarget.Width, renderTarget.Height);
}
stream.Dispose();
}
Okay, well, I narrowed it down a bit. I just took out the portion of the function that writes it to a file and just cast renderTarget to Texture2D and then rendered it, and it looks perfect. So clearly the problem is with saving the file. This doesn't completely solve my problem, but it at least gives me something to work with.