Capture screenshot of active window?

前端 未结 11 2523
春和景丽
春和景丽 2020-11-21 23:34

I am making a screen capturing application and everything is going fine. All I need to do is capture the active window and take a screenshot of this active window. Does an

11条回答
  •  天命终不由人
    2020-11-22 00:22

    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);
    }
    

    for capturing current window use

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

提交回复
热议问题