在XNA中拍摄屏幕截图

Alo*_*kin 5 c# xna screenshot

如何在XNA中拍摄屏幕截图?没有System.Drawing.Graphics.CopyFromScreen或没有Win32API ,有可能吗?如果不可能,是否有任何办法吸引System.Drawing.Bitmap游戏?

我希望它需要一个屏幕截图,然后以全屏模式加载游戏,然后打印该截图。

谢谢。

Pet*_*ter 5

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

首先在游戏的LoadContent方法中创建ResolveTexture2D:

renderTargetTexture = new ResolveTexture2D(
        graphics.GraphicsDevice,
        graphics.GraphicsDevice.PresentationParameters.BackBufferWidth,
        graphics.GraphicsDevice.PresentationParameters.BackBufferHeight, 1,
        graphics.GraphicsDevice.PresentationParameters.BackBufferFormat);
Run Code Online (Sandbox Code Playgroud)

然后在绘制场景后在Draw方法中解析后台缓冲区:

graphics.GraphicsDevice.ResolveBackBuffer(renderTargetTexture);
Run Code Online (Sandbox Code Playgroud)

最后,当游戏在Draw方法中暂停时,使用spritebatch绘制捕获的后缓冲区:

spriteBatch.Draw(renderTargetTexture, Vector2.Zero, Color.White);
Run Code Online (Sandbox Code Playgroud)

如果要使图像为灰度,则需要编写一个像素着色器,并在LoadContent中加载效果文件,然后在使用spritebatch绘制纹理之前设置效果。