Capture the Screen using C#

Posted by Peermohamedmydeen under Windows Forms category on | Points: 40 | Views : 3743
Use the NameSpace Drawing.Imaging.

using System.Drawing.Imaging;

private static Bitmap ScreenImage; 
private static Graphics ScreenGraphic;

private void CaptureScreen()
ScreenImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

ScreenGraphic= Graphics.FromImage(ScreenImage); //Convert from image to graphic

ScreenGraphic.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

ScreenImage .Save(AppDomain.CurrentDomain.BaseDirectory + "MyScreenShot", ImageFormat.Png);


Use this.Hide(); and this.Show(); when call the CaptureScreen() method, otherwise our form will appear on the screen shot.

Comments or Responses

Login to post response