Take screen shot in XNA

2019-01-23 09:25发布

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.

1条回答
Evening l夕情丶
2楼-- · 2019-01-23 10:14

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.

查看更多
登录 后发表回答