devxlogo

Create and Save Thumbnails of Web Pages

Create and Save Thumbnails of Web Pages

You can use the .NET WebBrowser control to take thumbnails or full-size screenshots of loaded web pages, and then use the Bitmap class to save them locally.

For example, to generate a thumbnail, use:

public Bitmap GenerateThumbnail(string url){    //rendered at full size    return GenerateScreenshot(url, -1, -1);}public Bitmap GenerateThumbnail(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;} 

Here are a couple of examples of calling the preceding code:

// Generate thumbnail of www.devx.com at 1024x768 resolutionBitmap thumbnail = GenerateThumbnail("http://www.devx.com", 1024, 768);// Generate thumbnail of a www.devx.com at full sizethumbnail = GenerateThumbnail("http://www.devx.com");
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist