5

How can I take a screen shot of the screen in XNA? Is it possible without System.Drawing.Graphics.CopyFromScreen or Win32API? If it's not possible, Is there any way to draw a System.Drawing.Bitmap to the game?

I want that it'll take a screen screenshot, then load the game in full screen mode, and then print the screenshot.

Thanks.

Alon Gubkin
  • 56,458
  • 54
  • 195
  • 288

1 Answers1

5

http://www.gamedev.net/community/forums/topic.asp?topic_id=537265&whichpage=1&#3469331

First create a ResolveTexture2D in your game's LoadContent method:

renderTargetTexture = new ResolveTexture2D(
        graphics.GraphicsDevice,
        graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
        graphics.GraphicsDevice.PresentationParameters.BackBufferHeight, 1,
        graphics.GraphicsDevice.PresentationParameters.BackBufferFormat);

Then resolve the back buffer in your Draw method after you draw your scene:

graphics.GraphicsDevice.ResolveBackBuffer(renderTargetTexture);

Finally, draw your captured back buffer using a spritebatch when your game is paused in your Draw method:

spriteBatch.Draw(renderTargetTexture, Vector2.Zero, Color.White);

If you want the image to be grayscale, you'll need to write a pixel shader and load it with an effect file in your LoadContent, then set the effect before drawing the texture with the spritebatch.

Peter
  • 37,042
  • 39
  • 142
  • 198