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

时间:2018-07-06 07:24:18

标签: c# .net winforms screenshot 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:\Users\Desktop\test.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }

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

2 个答案:

答案 0 :(得分:0)

这将为您提供整个窗口的屏幕截图

Rectangle bounds = Screen.GetBounds(Point.Empty);
using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
    using(Graphics g = Graphics.FromImage(bitmap))
    {
         g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
    }
    bitmap.Save("test.jpg", ImageFormat.Jpeg);
}

答案 1 :(得分:0)

当然,这很简单:

TextView

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

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