Home » C# scripts » Scripts to take screenshot of a page using c#

Scripts to take screenshot of a page using c#

// method takes filepath as a parameter to save captured image in specified location
// file path example: filePath=@"C:\myFile\loginPage.bmp";
// Bitmap and Graphics classes present inside System.Drawing
// Screen.PrimaryScreen.Bounds.Width is used to get system width. Screen class present inside System.windows.forms

 public void screenShotCapture(string FilePath) 
  Bitmap bmap= new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); 
  Graphics gpc= Graphics.FromImage(bmap as System.Drawing.Image); 
  gpc.CopyFromScreen(25, 25, 25, 25, bmap.Size); 
  bmap.Save(FilePath, ImageFormat.Bmp); 


Leave a comment

Your email address will not be published. Required fields are marked *