Пример #1
0
        private void TakeScreenshot(string cmdId, string args)
        {
            if (this.browser == null || this.browser.MainHWND == IntPtr.Zero || this.browser.CanvasHWND == IntPtr.Zero)
            {
                return;
            }

            if (this.StartInfo == null || args == null)
            {
                return;
            }


            String[] argsarr = Regex.Split(args, "~");

            int width  = -1;
            int height = -1;

            if (argsarr == null || argsarr.Length == 0)
            {
                return;
            }

            String key = argsarr[0];

            if (argsarr.Length >= 3)
            {
                try { width = int.Parse(argsarr[1]); }
                catch { }
                try { height = int.Parse(argsarr[2]); }
                catch { }
            }

            bool maximize = true;

            if (argsarr.Length == 4)
            {
                try
                {
                    maximize = (int.Parse(argsarr[3]) == 1);
                }
                catch { }
            }

            Stream outs = new ScreenshotsDumpFilesInfo(this.StartInfo).Open(FileAccess.Write, key);

            if (outs != null)
            {
                Bitmap bm = ScreenGrabber.GrabScreen(browser.MainHWND, browser.CanvasHWND, maximize);

                if (bm != null)
                {
                    if (width != -1 && height != -1)
                    {
                        bm = ResizeBitmap(bm, width, height);
                    }
                    bm.Save(outs, ImageFormat.Jpeg);

                    try
                    {
                        bm.Dispose();
                    }
                    catch
                    {
                    }
                }
            }
        }