Capture screenshot of active window?

前端 未结 11 2232
春和景丽
春和景丽 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:08

    Use the following code :

                // Shot size = screen size
                Size shotSize = Screen.PrimaryScreen.Bounds.Size;
    
                // the upper left point in the screen to start shot
                // 0,0 to get the shot from upper left point
                Point upperScreenPoint = new Point(0, 0);
    
                // the upper left point in the image to put the shot
                Point upperDestinationPoint = new Point(0, 0);
    
                // create image to get the shot in it
                Bitmap shot = new Bitmap(shotSize.Width, shotSize.Height);
    
                // new Graphics instance 
                Graphics graphics = Graphics.FromImage(shot);
    
                // get the shot by Graphics class 
                graphics.CopyFromScreen(upperScreenPoint, upperDestinationPoint, shotSize);
    
                // return the image
                pictureBox1.Image = shot;
    

提交回复
热议问题