捕获最小化远程桌面的屏幕截图
我有以下 C# 代码,用于捕获远程桌面 (RDP) 会话内的屏幕截图。当会话处于活动状态时,它工作正常,但如果我最小化会话,则会因无效句柄异常而失败。
有什么方法可以实现此功能,或者当会话最小化时屏幕基本上“消失”了?
string filename = @"C:\Snap.png";
Size bitmapSize = new Size( Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height );
using (Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb))
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen( // Exception thrown here
new Point(0, 0),
new Point(0, 0),
bitmapSize);
bitmap.Save(filename, ImageFormat.Png);
}
I have the following C# code, which I am using to capture a screenshot inside a remote desktop (RDP) session. It works fine when the session is active, but fails with an invalid handle exception if I minimize the session.
Is there any way to make this work, or is the screen essentially "gone" when the session is minimized?
string filename = @"C:\Snap.png";
Size bitmapSize = new Size( Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height );
using (Bitmap bitmap = new Bitmap(bitmapSize.Width, bitmapSize.Height, PixelFormat.Format24bppRgb))
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen( // Exception thrown here
new Point(0, 0),
new Point(0, 0),
bitmapSize);
bitmap.Save(filename, ImageFormat.Png);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须暂时恢复窗口,捕获并再次最小化它。 此链接展示了如何静默执行此操作
You have to temporarily restore the window, capture, and minimize it again. This link shows how to do it silently