Take a screenshot in XNA

How can I take a screenshot in XNA? Is this possible without System.Drawing.Graphics.CopyFromScreen or Win32API? If this is not possible, is there a way to make a System.Drawing.Bitmap for the game?

I want him to take a screenshot, then load the game in full screen mode, and then print the screenshot.

Thanks.

+4
source share
1 answer

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

First create a ResolveTexture2D in your game LoadContent Method:

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

Then enable the back buffer in the drawing method after painting the scene:

 graphics.GraphicsDevice.ResolveBackBuffer(renderTargetTexture); 

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

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

If you want the image to be grayscale, you need to write a pixel shader and load it using the effects file into your LoadContent, and then set the effect before painting the texture using spritebatch.

+4
source

All Articles