[Mono-dev] WebBrowser Thumbnail
Quandary
quandary82 at hailmail.net
Sat Mar 26 04:14:42 EDT 2011
Hi,
Question: Why does the below code (to take a thumbnail of a website)
hang forever at:
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
? It works with .NET on Windows.
And furthermore, is it possible to take a WebSite Thumbnail with
webkit-sharp ?
I have not found a way.
I'm now resorting to khtml2png.
Code:
public Bitmap GenerateScreenshot(string url)
{
// This method gets a screenshot of the webpage
// rendered at its full size (height and width)
return GenerateScreenshot(url, -1, -1);
}
public Bitmap GenerateScreenshot(string url, int width, int height)
{
// Load the webpage into a WebBrowser control
WebBrowser wb = new WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }
// Set the size of the WebBrowser control
wb.Width = width;
wb.Height = height;
if (width == -1)
{
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
}
if (height == -1)
{
// Take Screenshot of the web pages full height
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));
wb.Dispose();
return bitmap;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110326/993cc566/attachment.html
More information about the Mono-devel-list
mailing list