There’s a few ways to do this, but this is the best way I’ve come across so far.
In your draw function, just add this code ( AFTER base.Draw(), other wise any DrawableGameComponents in your project won’t appear in the shot ):
// variable screenShot gets set to true
// in Update() if someone presses spacebar
if( screenShot == true )
{
ResolveTexture2D rt = new ResolveTexture2D(
GraphicsDevice,
graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight,
1,
SurfaceFormat.HalfVector4 ); // this format works with my GPU. Yours may be different.
// If not working, try a few different ones.
// actually grab the current set of color values from the back buffer
GraphicsDevice.ResolveBackBuffer( rt );
// Save out to disk.
rt.Save( "screenshot.png", ImageFileFormat.Png ); // saves into same dir as .exe
screenShot = false ;
}
Of course you could timestamp the screen shot using DateTime.Now.ToString(“format string”).