Taking screenshots in XNA

Wouldn’t it be nice if it was simple to add screenshot functionality to your games? People who play your games could easily post pictures online, gathering even more interest in and publicity for your game?

I’ve gathered some screenshot code I found on the web (credits in the code) in a little GraphicsDevice extension method. If you aren't familiar with extension methods, basically they add new functionality to existing classes - in this case adds two new methods to Microsoft's GraphicsDevice class.

call the GraphicsDevice.PrepareScreenshot() before the spriteBatch.Begin()

call the GraphicsDevice.SaveScreenshot() after spriteBatch.End()

If you pass the SaveScreenshot method a filename or path then that filename will be used. If you don’t then screendumps will be saved in a file called Screenshot_001.png, Screenshot_002.png, etc. in the running game’s folder.

In the code sample below, the screenshot is prepared on line 9 and the screenshot is taken on line 34.

4 Responses to “Taking screenshots in XNA”

Okay, that sounds like you're not calling GraphicsDevice.PrepareScreenShot _before_ SpriteBatch.Begin, and GraphicsDevice.SaveScreenShot _after_ SpriteBatch.End ....?
Have you tried downloading the codesample and comparing it with your code?
If you're still at a loss to the purple screen, send me the code for your Draw() method - my email is: "kr [at] rup [dot] dk" and I'll have a look at it