【发布时间】: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