Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Take screen shot in XNA

Tags:

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.

like image 521
Alon Gubkin Avatar asked Nov 21 '09 11:11

Alon Gubkin


1 Answers

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.

like image 60
Peter Avatar answered Oct 11 '22 22:10

Peter