PrintScreen 源代码/模拟
我想拍摄一张全屏 direct3D 游戏的照片。我知道我需要创建一个“覆盖”,这在 c# 中更难,并且我发现使用 printscreen (而不是将其粘贴到 mspaint 中)确实捕获了游戏窗口。
我最终得到了这个不稳定的代码:
try
{
SendKeys.SendWait("{PRTSC}");
Thread.Sleep(100);
if (Clipboard.ContainsImage())
return Clipboard.GetImage();
}
catch (Exception)
{
throw;
}
Bitmap bitmap = new Bitmap(1, 1);
return bitmap;
这个代码有时可以工作,有时会抛出一个ExternalException,有时Clipboard.ContainsImage()返回false,它只是返回一个1,1大小的图像。
我想尝试改进该代码,这样我就不必依赖将某些内容复制到剪贴板所需的时间(使用 thread.sleep(20000),它会工作,但此代码只是每 800 毫秒执行一次的较大代码)。
因此,我需要有关如何更可靠地发送密钥或获取 printscreen 使用的方法的想法。
I would like to take a picture of a fullscreen direct3D game. I know I need to create an "overlay" which is harder in c# and I found out that using printscreen (and than pasting it in mspaint) does capture the game window.
I ended up with this unstable code :
try
{
SendKeys.SendWait("{PRTSC}");
Thread.Sleep(100);
if (Clipboard.ContainsImage())
return Clipboard.GetImage();
}
catch (Exception)
{
throw;
}
Bitmap bitmap = new Bitmap(1, 1);
return bitmap;
This code sometimes work, sometimes it throws an ExternalException and sometimes and Clipboard.ContainsImage() returns false and it simply returns a 1,1 sized image.
I would like to try and improve that code so I won't have to rely on the time it takes to copy something to the clipboard (with thread.sleep(20000), it'll work but this code is just a part of a larger code that executes every 800ms).
So I need ideas on how to send keys more reliably or get the that method printscreen uses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)