如何在XNA中拍摄屏幕截图?没有System.Drawing.Graphics.CopyFromScreen
或Win32API可以吗?如果不可能,有没有办法在游戏中绘制System.Drawing.Bitmap
?
我希望它会采用屏幕截图,然后以全屏模式加载游戏,然后打印屏幕截图。
感谢。
答案 0 :(得分:4)
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);
然后在绘制场景后解决Draw方法中的后台缓冲区:
graphics.GraphicsDevice.ResolveBackBuffer(renderTargetTexture);
最后,当您在Draw方法中暂停游戏时,使用spritebatch绘制捕获的后台缓冲区:
spriteBatch.Draw(renderTargetTexture, Vector2.Zero, Color.White);
如果您希望图像为灰度,则需要编写像素着色器并在LoadContent中使用效果文件加载它,然后在使用spritebatch绘制纹理之前设置效果。