Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's some code that I posted on my blog a few weeks ago that does this:</p> <p><a href="http://pietschsoft.com/post.aspx?id=2a628f30-fe83-4e44-a34b-f31be76d1b4f" rel="nofollow noreferrer">C#: Generate WebPage Thumbnail Screenshot Image</a></p> <p>I'll also post the code for it below:</p> <pre><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; } </code></pre> <p>Here's some example usages:</p> <pre><code>// Generate thumbnail of a webpage at 1024x768 resolution Bitmap thumbnail = GenerateScreenshot("http://pietschsoft.com", 1024, 768); // Generate thumbnail of a webpage at the webpage's full size (height and width) thumbnail = GenerateScreenshot("http://pietschsoft.com"); // Display Thumbnail in PictureBox control pictureBox1.Image = thumbnail; /* // Save Thumbnail to a File thumbnail.Save("thumbnail.png", System.Drawing.Imaging.ImageFormat.Png); */ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload