winforms - Windows 窗体 : Screen capture when running non-graphically (i. e.屏幕保护程序处于事件状态)

标签 winforms testing directx

我有一个图形密集型应用程序,它是基于 DirectX 和 Windows 窗体构建的。它有一个自动化和重放框架,围绕它构建了一个自动化测试系统。不幸的是,当测试在夜间构建期间无人值守运行时,显示处于非事件状态或与屏幕保护程序绑定(bind),我们的 IT 安全策略不允许我们禁用它。

所以我的问题是:有没有办法对在没有显示器的情况下运行的应用程序进行“屏幕”捕获?我想确保显卡已启用,以便我的渲染管道是相同的,但测试框架不需要关心显示器的状态。

非常感谢任何帮助!

最佳答案

既然你提到了渲染管道,那么我假设你正在使用 Direct3d,如果是这样,你可以保存帧的后备缓冲区。当我还在使用 VB.Net + MDX 时,我就这样做了

Dim tempSurface As Direct3D.Surface
tempSurface = device.GetBackBuffer(0, 0, Direct3D.BackBufferType.Mono)
Direct3D.SurfaceLoader.Save(tempFilename, Direct3D.ImageFileFormat.Png, tempSurface)

您可以轻松转换为您选择的任何编程语言,它基本上是调用 Direct3d 的 API。不过,您需要将后台缓冲区和 Present 参数配置为

' Need to use flip to enable screen capture
presentParams.SwapEffect = Direct3D.SwapEffect.Flip 
presentParams.PresentationInterval = Direct3D.PresentInterval.One

关于winforms - Windows 窗体 : Screen capture when running non-graphically (i. e.屏幕保护程序处于事件状态),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/183118/

相关文章:

testing - Moxios - 类型错误 : Cannot read property 'adapter' of undefined

testing - UFT 无法识别 Web 浏览器上的 Windows 框架

c++ - 不同的窗体

c# - StartPosition 设置为 CenterPosition 但我的表格没有居中

c# - 使用本地化枚举作为数据源

android - 需要帮助设置 RoboSpock

c++ - 二进制 '-' : 'DirectX::XMVECTOR' does not define this operator or a conversion (migrating from xnamath to DirectXMath is not so easy)

c++ - 如何绕过警告 "rvalue used as lvalue"?

c# - 事件处理程序影响 CLR 中的垃圾回收

c# - 标签上的 "Invoke or BeginInvoke cannot be called on a control until"