我有一个显示一些银色灯光控件的网页。我需要以编程方式截取此网页的屏幕截图。
当前使用 System.Windows.Forms.WebBrowser 控件进行屏幕截图。
当我为普通页面截屏时,Forms.WebBrowser 工作正常。但是对于具有 Silverlight 控件的页面,它不起作用。
我的截图代码如下: Bitmap bitmap = null; 使用 (WebBrowser webBrowser = new WebBrowser()) { webBrowser.ScrollBarsEnabled = false; webBrowser.ScriptErrorsSuppressed = true;
// Set the size of the WebBrowser control
webBrowser.Width = width;
webBrowser.Height = height;
// Load the webpage into a WebBrowser control
webBrowser.Navigate(url);
while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
if (width == -1)
{
// Take Screenshot of the web pages full width
webBrowser.Width = webBrowser.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
webBrowser.Height = webBrowser.Document.Body.ScrollRectangle.Height;
}
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
bitmap = new Bitmap(webBrowser.Width, webBrowser.Height);
webBrowser.DrawToBitmap(bitmap, new Rectangle(0, 0, webBrowser.Width, webBrowser.Height));
}