【问题标题】:Chrome webpage screenshotChrome 网页截图
【发布时间】:2014-03-18 15:54:50
【问题描述】:

当尝试使用 WebBrowser Controller 为 chrome 的网页屏幕截图执行 C# 代码时,我得到的屏幕截图是由 IE 而不是由 Chrome 呈现的网页(我尝试捕获的网站由 Chrome、FireFox 和即)。

你能解释一下如何为Chrome而不是IE渲染的网页制作屏幕截图吗? Ps:我之前用过ChromeDriver,但它只是捕获网页的可见部分, 非常感谢

这是截取网页屏幕截图的方法

`public static void TakeScreenShotChrome(WebBrowser WB, string url, string path)
        // Load the webpage into a WebBrowser control WebBrowser
    {

        WB.ScrollBarsEnabled = false;
        WB.ScriptErrorsSuppressed = true;
        WB.Navigate(url);


        while (WB.ReadyState != WebBrowserReadyState.Complete)
        {

            //Application.DoEvents();
            Thread.Sleep(1000);

        }

        // Take Screenshot of the web pages full width 
        WB.Width = WB.Document.Body.ScrollRectangle.Width;
        // Take Screenshot of the web pages full height 
        WB.Height = WB.Document.Body.ScrollRectangle.Height;


        Bitmap bitmap = new Bitmap(WB.Width, WB.Height);
        WB.DrawToBitmap(bitmap, new Rectangle(0, 0, WB.Width, WB.Height));
        bitmap.Save(path,ImageFormat.Png);
        WB.Dispose();



    }`

【问题讨论】:

    标签: c# screenshot


    【解决方案1】:

    您正在使用WebBrowser 控件。 WebBrowser 是 IE。如果您希望 Chrome 使用类似 AwesomiumPhantomJS 的内容。

    我个人只是编写 PhantomJS 脚本,您可以渲染整个页面或定义视口大小并将其直接渲染到图像。

    【讨论】:

    • 嗯,我明白了,你能给我一个如何使用 Awesomium 或 PhantomJS 的链接吗?
    • 这两个项目都已经提供了示例。对于 Phantom,您需要使用 Process.Start(),因为它是一个外部应用程序。
    • 感谢劳埃德的澄清
    猜你喜欢
    • 2022-10-14
    • 1970-01-01
    • 2013-06-15
    • 2010-09-08
    • 2011-10-25
    • 1970-01-01
    • 2019-08-09
    • 2014-08-24
    相关资源
    最近更新 更多