保存WebBrowser控件sceenshot而不是在全屏幕 [英] Save WebBrowser control sceenshot while not in full screen

查看:214
本文介绍了保存WebBrowser控件sceenshot而不是在全屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的只是包含描述这里 WebBrowser控件内的网页截图和这里,但我有一个问题:如果WebBrowser控件不全屏,截图被裁剪为控件的大小。

I get the screenshot of a webpage contained inside a WebBrowser control just as described here and here, but I have a problem: if the WebBrowser control is not at full screen, the screenshot gets cropped to the size of the control.

是否可以保存整个网页的截图,如果WebBrowser控件不全屏?

Is it possible to save a screenshot of the whole page if the WebBrowser control is not at full screen?

这是我目前使用保存的截图代码:

This is the code I'm currently using to save the screenshot:

private void SaveBrowserScreenshot(WebBrowser browser, string path, string name)
{
    const int width = 1024;
    const int height = 768;
    const string extension = ".png";

    using (var bitmap = new Bitmap(width, height))
    {
        var rect = new Rectangle(0, 0, width, height);
        browser.DrawToBitmap(bitmap, rect);

        using (var image = bitmap)
        {
            using (var graphic = Graphics.FromImage(image))
            {
                graphic.CompositingQuality = CompositingQuality.HighQuality;
                graphic.SmoothingMode = SmoothingMode.HighQuality;
                graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;

                image.Save(String.Concat(path, "\\", name, extension), ImageFormat.Png);
            }
        }
    }
}

性能是不是因为这个问题将永远不会在生产中使用。

Performance is not an issue since this will never be used in production.

推荐答案

你可以做一个按钮,当它使快照它接受当前的URL并提出了到一个新的WeBrowser对象,然后扩展到更大的尺寸,所以当它采取截图它的全尺寸?

Could you make a button that when it takes the snapshot it takes the current URL and puts that into a new WeBrowser object which is then expanded to a much bigger size so when it takes the screenshot it's full size?

这篇关于保存WebBrowser控件sceenshot而不是在全屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆