Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
        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);
                }
            }
        }