Skip navigation

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( 
  graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight,
  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”).


One Comment

    • Anonymous
    • Posted December 24, 2014 at 9:56 am
    • Permalink


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: