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
Click to Enlarge