在全屏模式下运行游戏时,如何使用 C# 和 XNA 制作屏幕截图并将其保存到硬盘?
问问题
10885 次
3 回答
7
4
下面看看这段代码。
count += 1;
string counter = count.ToString();
int w = GraphicsDevice.PresentationParameters.BackBufferWidth;
int h = GraphicsDevice.PresentationParameters.BackBufferHeight;
//force a frame to be drawn (otherwise back buffer is empty)
Draw(new GameTime());
//pull the picture from the buffer
int[] backBuffer = new int[w * h];
GraphicsDevice.GetBackBufferData(backBuffer);
//copy into a texture
Texture2D texture = new Texture2D(GraphicsDevice, w, h, false, GraphicsDevice.PresentationParameters.BackBufferFormat);
texture.SetData(backBuffer);
//save to disk
Stream stream = File.OpenWrite(counter + ".jpg");
texture.SaveAsJpeg(stream, w, h);
stream.Dispose();
texture.Dispose();
于 2011-11-09T11:00:47.937 回答
0
这个答案向您展示了如何截取屏幕截图。在这个例子中,它会在每次渲染时保存一个图像,所以你只需要将它移动到一个你可以在想要保存屏幕截图时调用的函数中。
于 2011-04-03T14:54:45.817 回答