我抓住从下面的链接一些代码,以生成从Web浏览器控制的屏幕截图: http://pietschsoft.com/post/2008/07/C-Generate-WebPage-Thumbmail-Screenshot-Image.aspx生成截图从web浏览器控件
然后,我修饰成像的扩展方法,以便:
public static Bitmap GetScreenshot(this WebBrowser webBrowser)
{
// Load the webpage into a WebBrowser control
using (WebBrowser wb = new WebBrowser())
{
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(webBrowser.Url);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
// Set the size of the WebBrowser control
wb.Width = wb.Document.Body.ScrollRectangle.Width;
wb.Height = wb.Document.Body.ScrollRectangle.Height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
return bitmap;
}
}
它适用于大多数网页,但我试图将其用于SharePoint网站,并且图像每次都以250x250出现。 :-s
这里可以给我一个解决方案的任何天才吗?
在此先感谢
好没关系,这种理论......我被厚厚的...这是null,因为DocumentCompleted没有被称为然而,在任何情况下,我仍然有问题,大多数时间也都是空白的白色图像。 – Matt 2010-10-11 08:24:44