Take Screen Shot in 4 Steps using C#

Declare bitmap ad Graphics like below

  1. private static Bitmap bmpScreen;  
  2. private static Graphics gfxScreen;  

Then write the Following line in the command button:

  1. if (saveFileDialog1.ShowDialog() == DialogResult.OK)    
  2. {    
  3.     bmpScreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);    
  4.     // Create a graphics object from the bitmap    
  5.     gfxScreen = Graphics.FromImage(bmpScreen);    
  6.     // Take the screenshot from the upper left corner to the right bottom corner    
  7.     gfxScreen.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);    
  8.     // Save the screenshot to the specified path that the user has chosen    
  9.     bmpScreen.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);    
  10. }  

 

We can change the pixel format, there are verity of different Format Enumeration are available. check the below link.

I have used the code inside the saveas dialog box. it help us to Save the Image in the specified location.

or

We can specify the location manually like below.

  1. bmpScreen.Save(image location here, ImageFormat.Jpeg);  

Have Fun!!!

Thanks