Articles → CSHARP → Capture Screenshot In C#

Capture Screenshot In C#






Code


public void CaptureMyScreenShot() {
  // Create a bitmap object
  Bitmap myscreenbitmap = new Bitmap(800, 600, PixelFormat.Format32bppArgb);
  Rectangle captureRectangle = System.Windows.Forms.Screen.AllScreens[0].Bounds;
  Graphics captureGraphics = Graphics.FromImage(myscreenbitmap);

  //Copying Image from The Screen
  captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size);

  System.IO.MemoryStream ms = new MemoryStream();
  myscreenbitmap.Save(ms, ImageFormat.Jpeg);

  using(FileStream fs = new FileStream("myfile.jpg", FileMode.OpenOrCreate)) {
    ms.WriteTo(fs);
    fs.Flush();
  }
}



Output


Picture showing the output of capturing screenshot using C#
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, August 26, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250