2009-11-21 160 views
4

如何在XNA中拍摄屏幕截图?没有System.Drawing.Graphics.CopyFromScreen或Win32API可能吗?如果不可能,是否有任何方法可以将System.Drawing.Bitmap绘制到游戏中?在XNA中拍摄屏幕截图

我想要它将采取屏幕截图,然后以全屏模式加载游戏,然后打印屏幕截图。

谢谢。

+0

想要在游戏加载之前截取系统*的截图,或者在游戏运行时截取游戏截图? – 2009-11-25 16:38:12

+0

游戏加载前系统的截图 – 2009-11-25 19:51:06

回答

4

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

首先在你的游戏的LoadContent方法创建一个ResolveTexture2D:

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

然后解决您的Draw方法后缓冲区绘制场景后:

graphics.GraphicsDevice.ResolveBackBuffer(renderTargetTexture); 

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

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

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

+0

它不工作,它只是显示默认的XNA蓝色CornflowerBlue屏幕。 – 2009-11-21 12:14:35

+0

问题是你的结局,就我所见,该代码没有问题 – Martin 2009-11-24 14:15:01

+1

之后我将如何保存此屏幕截图? – 2011-12-24 11:08:36