//CaptureScreenToFile public Bitmap CaptureDeskTopRectangle(Rectangle CapRect, int CapRectWidth, int CapRectHeight) { /// Returns BitMap of the region of the desktop, similar to CaptureWindow, but can be used to /// create a snapshot of the desktop when no handle is present, by passing in a rectangle /// Grabs snapshot of entire desktop, then crops it using the passed in rectangle's coordinates ScreenShot.ScreenCapture SC = new ScreenShot.ScreenCapture(); Bitmap bmpImage = new Bitmap(SC.CaptureScreen()); Bitmap bmpCrop = new Bitmap(CapRectWidth, CapRectHeight, bmpImage.PixelFormat); Rectangle recCrop = new Rectangle(CapRect.X, CapRect.Y, CapRectWidth, CapRectHeight); Graphics gphCrop = Graphics.FromImage(bmpCrop); Rectangle recDest = new Rectangle(0, 0, CapRectWidth, CapRectHeight); gphCrop.DrawImage(bmpImage, recDest, recCrop.X, recCrop.Y, recCrop.Width, recCrop.Height, GraphicsUnit.Pixel); return(bmpCrop); }
private static void TakeScreenshot() { ScreenShot.ScreenCapture SC = new ScreenShot.ScreenCapture(); try { Image bmTemp = SC.CaptureScreen(); bmTemp.Save(strFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); output += "Desktop captured to: " + strFilePath + "\n"; } catch (Exception ex) { output += ex.Message + "\n"; } }