private void TakeScreenshot(bool captureMouse) { if (captureMouse) { var bmp = ScreenCapturePInvoke.CaptureSelectedScreen(true, comboScreens.SelectedIndex); rwl.AcquireWriterLock(Timeout.Infinite); bmp.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", ImageFormat.Jpeg); rwl.ReleaseWriterLock(); bmp.Dispose(); bmp = null; return; } Rectangle bounds = Screen.GetBounds(Point.Empty); using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size); } rwl.AcquireWriterLock(Timeout.Infinite); bitmap.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", ImageFormat.Jpeg); rwl.ReleaseWriterLock(); } }
private void TakeScreenshot(bool captureMouse) { if (captureMouse) { var bmp = ScreenCapturePInvoke.CaptureSelectedScreen(true, comboScreens.SelectedIndex); rwl.AcquireWriterLock(Timeout.Infinite); bmp.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", ImageFormat.Jpeg); rwl.ReleaseWriterLock(); if (isPreview) { img = new MemoryStream(); bmp.Save(img, ImageFormat.Jpeg); imgPreview.Image = new Bitmap(img); } bmp.Dispose(); bmp = null; return; } Screen screen = Screen.AllScreens[comboScreens.SelectedIndex]; using (Bitmap bitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(screen.Bounds.X, screen.Bounds.Y, 0, 0, screen.Bounds.Size, CopyPixelOperation.SourceCopy); } rwl.AcquireWriterLock(Timeout.Infinite); bitmap.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", ImageFormat.Jpeg); rwl.ReleaseWriterLock(); if (isPreview) { img = new MemoryStream(); bitmap.Save(img, ImageFormat.Jpeg); imgPreview.Image = new Bitmap(img); } } }