问题描述
我正在尝试截取在 OpenGL 中创建的游戏的屏幕截图..
I'm trying to take screenshots of a game created in OpenGL..
我有这个代码:
_captureProcess.BringProcessWindowToFront();
ScreenCapture sc = new ScreenCapture();
Image img = sc.CaptureWindow(_process.MainWindowHandle);
来自:http://www.developerfusion.com/code/4630/capture-a-screen-shot/
IntPTR 是正确的!但是图像是全黑的!
The IntPTR is correct!But the image is completely black!
_process = 全屏游戏,OPENGL..
_process = Game in full screen, OPENGL..
如何才能实时截取屏幕截图而不出现黑屏?
How could I do to be able to take screenshots in real time, without getting the black screen?
推荐答案
您链接的代码示例取决于在 Windows XP 之前(包括 Windows XP)中可以找到的未定义行为:如果您创建了窗口,或将窗口移动到顶部并阻止它重新绘制,它会接收它下面的所有内容.这种行为从未被指定,但很多人利用它.
The code sample you linked depends on a undefined behavior one could find in Windows up until and including Windows XP: If you created, or moved a window to the top and prevented it from redrawing, it would receive the contents of everything beneath it. This behavior has nevern been specified but a lot of people exploited it.
Windows Vista 引入了合成,其中每个窗口都位于自己的屏幕外内存区域中,并且不与其他窗口交互.因此,您可以在清除的屏幕外缓冲区的黑色窗口中看到所有内容.
Windows Vista introduced compositing, where each window lives in its own off-screen memory area and doesn't interact with the other windows. Hence all you see in such a window in the black of the cleared off-screen buffer.
如何才能实时截取屏幕截图而不出现黑屏?
通过使用 Windows 提供的适当 API,即用于在 Vista 及更高版本中截取屏幕截图的 DWM API.
By using the proper APIs provided by Windows, namely the DWM API for taking screenshots in Vista and later.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa969540(v=vs.85).aspx
这篇关于如何使用 OpenGL 截取游戏截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!