Exemple #1
0
        private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var       browser = sender as WebBrowser;
            Rectangle body    = browser.Document.Body.ScrollRectangle;

            browser.Width  = body.Width;
            browser.Height = body.Height;

            using (var bitmap = new Bitmap(body.Width, body.Height))
            {
                IViewObject ivo = browser.Document.DomDocument as IViewObject;

                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    //get the handle to the device context and draw
                    IntPtr hdc = g.GetHdc();
                    ivo.Draw(1, -1, IntPtr.Zero, IntPtr.Zero,
                             IntPtr.Zero, hdc, ref body,
                             ref body, IntPtr.Zero, 0);
                    g.ReleaseHdc(hdc);
                }

                if (_captured != null)
                {
                    WebPageCapturedEventArgs args = new WebPageCapturedEventArgs()
                    {
                        Image = new DefaultImage(bitmap)
                    };
                    _captured(this, args);
                }
            }
        }
        private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var browser = sender as WebBrowser;
            Rectangle body = browser.Document.Body.ScrollRectangle;

            browser.Width = body.Width;
            browser.Height = body.Height;

            using (var bitmap = new Bitmap(body.Width, body.Height))
            {
                IViewObject ivo = browser.Document.DomDocument as IViewObject;

                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    //get the handle to the device context and draw
                    IntPtr hdc = g.GetHdc();
                    ivo.Draw(1, -1, IntPtr.Zero, IntPtr.Zero,
                                IntPtr.Zero, hdc, ref body,
                                ref body, IntPtr.Zero, 0);
                    g.ReleaseHdc(hdc);
                }

                if (_captured != null)
                {
                    WebPageCapturedEventArgs args = new WebPageCapturedEventArgs()
                    {
                        Image = new DefaultImage(bitmap)
                    };
                    _captured(this, args);
                }
            }
        }