3
我有一個顯示一些銀色燈光控件的網頁。我需要以編程方式截取此網頁的屏幕截圖。以網頁截圖(使用Silverlight控件)編程式
當前使用System.Windows.Forms.WebBrowser控件進行屏幕截圖。
Forms.WebBrowser在正常頁面截圖時正常工作。但對於使用Silverlight控件的頁面無效。
我的屏幕截圖代碼如下: 位圖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));
}
您是否找到答案?因爲我面臨同樣的問題。 – NLV 2011-05-10 17:21:41