在 c# -winforms 中捕获 teststack.white 窗口的屏幕截图



有人可以帮我编写代码来捕获teststack.white窗口的屏幕截图吗?我尝试了以下代码

Rectangle bounds = this.Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new System.Drawing.Point(bounds.Left, bounds.Top), System.Drawing.Point.Empty, bounds.Size);
}
bitmap.Save(@"C:UsersDesktoptest.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}

这将捕获表单的屏幕截图。如果代替这个.bounds,我键入teststack.white窗口边界,它说不能将system.windows.rect转换为system.drawing.rectangle?有人可以向我提供代码来对此进行排序吗?提前谢谢。

当然,这很容易:

Desktop.TakeScreenshot("C:\white-framework.png", System.Drawing.Imaging.ImageFormat.Png);

如果需要在捕获图像后对其进行操作,可以执行以下操作:

Bitmap bitmap = Desktop.CaptureScreenshot();

最新更新