private void TakeScreenshot(bool captureMouse) { if (captureMouse) { var bmp = ScreenCapturePInvoke.CaptureFullScreen(true, comboMonitors.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); } return; } else { var bmp = ScreenCapturePInvoke.CaptureFullScreen(false, comboMonitors.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); } return; } }
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.CaptureFullScreen(true); rwl.AcquireWriterLock(Timeout.Infinite); ImageCodecInfo myImageCodecInfo; System.Drawing.Imaging.Encoder myEncoder; EncoderParameter myEncoderParameter; EncoderParameters myEncoderParameters; myImageCodecInfo = GetEncoderInfo("image/jpeg"); myEncoder = System.Drawing.Imaging.Encoder.Quality; myEncoderParameters = new EncoderParameters(1); myEncoderParameter = new EncoderParameter(myEncoder, long.Parse(imglevel.Text)); myEncoderParameters.Param[0] = myEncoderParameter; bmp.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", myImageCodecInfo, myEncoderParameters); rwl.ReleaseWriterLock(); bmp.Dispose(); bmp = null; return; } Rectangle bounds = Screen.GetBounds(Point.Empty); Graphics g1 = Graphics.FromHwnd(IntPtr.Zero); //100%的时候,DPI是96;这条语句的作用时获取放大比例 float factor = g1.DpiX / 96; bounds.Width = bounds.Width * (int)factor; bounds.Height = bounds.Height * (int)factor; 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); ImageCodecInfo myImageCodecInfo; System.Drawing.Imaging.Encoder myEncoder; EncoderParameter myEncoderParameter; EncoderParameters myEncoderParameters; myImageCodecInfo = GetEncoderInfo("image/jpeg"); myEncoder = System.Drawing.Imaging.Encoder.Quality; myEncoderParameters = new EncoderParameters(1); myEncoderParameter = new EncoderParameter(myEncoder, long.Parse(imglevel.Text)); myEncoderParameters.Param[0] = myEncoderParameter; bitmap.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", myImageCodecInfo, myEncoderParameters); rwl.ReleaseWriterLock(); } }
private void TakeScreenshot(bool captureMouse) { if (captureMouse) { var bmp = ScreenCapturePInvoke.CaptureFullScreen(true); rwl.AcquireWriterLock(Timeout.Infinite); if (OnceTranslation.Checked) { bmp.Save(Application.StartupPath + "/OtherWebserver" + "/ScreenTask.jpg", ImageFormat.Jpeg); } else if (!OnceTranslation.Checked) { 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); } 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); if (OnceTranslation.Checked) { bitmap.Save(Application.StartupPath + "/OtherWebserver" + "/ScreenTask.jpg", ImageFormat.Jpeg); } else if (!OnceTranslation.Checked) { 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); } } }
private void TakeScreenshot(bool captureMouse) { if (captureMouse) { var bmp = ScreenCapturePInvoke.CaptureFullScreen(true); rwl.AcquireWriterLock(Timeout.Infinite); EncoderParameters parameters = new EncoderParameters(1); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (int)numJpegQuality.Value); bmp.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", GetEncoderInfo("image/jpeg"), parameters); rwl.ReleaseWriterLock(); if (isPreview) { img = new MemoryStream(); bmp.Save(img, ImageFormat.Jpeg); imgPreview.Image = new Bitmap(img); } 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); EncoderParameters parameters = new EncoderParameters(1); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (int)numJpegQuality.Value); bitmap.Save(Application.StartupPath + "/WebServer" + "/ScreenTask.jpg", GetEncoderInfo("image/jpeg"), parameters); rwl.ReleaseWriterLock(); if (isPreview) { img = new MemoryStream(); bitmap.Save(img, ImageFormat.Jpeg); imgPreview.Image = new Bitmap(img); } } }
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); } } }
private void TakeScreenshot(bool captureMouse) { Rectangle captureBounds = ScreenFunctions.GetScreenBounds(ScreenInfo); if (captureMouse) { var bmp = ScreenCapturePInvoke.CaptureScreen(captureBounds, true); 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); } return; } using (Bitmap bitmap = new Bitmap(captureBounds.Width, captureBounds.Height)) { using (Graphics g = Graphics.FromImage(bitmap)) { g.CopyFromScreen(new Point(captureBounds.Left, captureBounds.Top), Point.Empty, captureBounds.Size); } 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); } } }