Capture Desktop Screenshot Using Windows Application

In this blog we will discuss how take screenshot of desktop using Windows Application.
Let's see how it can be implemented:
Step 1: Add the following namespaces which helps for generating image:
  1. using System.Windows.Forms;
  2. using System.Drawing.Imaging;
Step 2: Add the following code to capture the screenshot and save it to drive:
  1. Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);  
  2. Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);  
  3. graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);  
  4. bitmap.Save(@"D:\MyDemo\Reports\ScreenShot.bmp", ImageFormat.Jpeg);  
In preceding code: 
Line 1: It is fetching computer screen height and width. 
Line 2: Creating graphics object to draw/generate image.
Line 3: CopyFromScreen() method is copying background image and generate image through graphics object.
Line 4: It is saving the image to physical folder. 
                           Figure 1: Captured screenshot in Drive
Hope this helps you.