Click here to Skip to main content
11,411,922 members (64,641 online)
Click here to Skip to main content

Webpage thumbnailer

, 17 Aug 2006
Rate this:
Please Sign up or sign in to vote.
An article on how to get a webpage thumbnail and give your favorite links a face.

Introduction

Once upon a time, I got an idea to have a thumbnail of a webpage associated with each URL that I had on my list. Sort of a URL with "face" Smile | :) . I began to research on how to implement it, and found no solution for it in the open software domain. Many that I found were commercial products in the form of components and standalone programs. I'm just a poor programmer, and couldn't spend much to buy such a component. I was sure that there would be a way (even several) to achieve this goal without touching my child's spare money. And what I present in this article is what I found.

Using the code

Before you get into the code, you can build it and play around with it. The URL should be in a form http://www.yoursite.com, for example. I didn't write URL validation code, so you have to be careful about it. The project is very simple, and there are only a couple of points that I have to mention. To get the thumbnail image of the webpage, I use the WebBrowser component that comes with Visual Studio 2005 and is a part of the .NET framework v.2. I placed it on a BrowserForm, and set the size of the form to approximately 600 to 800 pixels to get enough visual data. Then, the BrowserForm is initialized, but is actually never shown. And this makes a trick.

private void TestForm_Load(object sender, EventArgs e) {
 browserForm = new BrowserForm(); 
}

What I have to do then is to take a snapshot of the WebBrowser after the page is loaded. That's all!

  Bitmap docImage = new Bitmap(600, 800);
  webBrowser1.DrawToBitmap(docImage, new Rectangle(webBrowser1.Location.X, 
          webBrowser1.Location.Y, webBrowser1.Width, webBrowser1.Height));
}

The page takes some time to load, and because of that, I've split the getting of the image in to three steps:

  1. I call the method getImageFromUrl(string url) on a BrowserForm that starts downloading the page from a given URL.
  2. The WebBrowser event DocumentCompleted is handled by the procedure webBrowser1_DocumentCompleted. It sets the image of the current DocPic object.
  3. The setter of the current DocPic object triggers the refreshPicture event that updates the displayed picture. Some resizing is made on place.

All code provided is purely for demonstration purposes only, so don't try to find design issues in it. You'll certainly find it if you try.

History

It's nice to know that on your website I can write history Smile | :) . Thanks to the admin!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

dooskoobi
Web Developer
Belgium Belgium
No Biography provided

Comments and Discussions

 
Questionplease provide alternative version Pinmembersneha kavinkar24-Jun-12 22:23 
GeneralThanks PinmemberMember 78098223-Apr-11 20:39 
Questionapplet problem Pinmemberdomartins10-May-08 8:55 
QuestionHow save image Pinmemberrashidpervaiz087-Feb-08 0:22 
GeneralReal height PinmemberBizounours19-Nov-07 3:58 
AnswerRe: Real height Pinmemberdooskoobi19-Nov-07 10:42 
GeneralRe: Real height PinmemberBizounours19-Nov-07 22:07 
AnswerRe: Real height - SOLUTION Pinmembertfpds12-Dec-07 4:28 
QuestionBlank Image on Websites with Java Applets PinmemberJon Ebersole9-Feb-07 13:58 
AnswerRe: Blank Image on Websites with Java Applets PinmemberWei Tian23-Mar-09 21:26 
QuestionHow to fix blank image? PinmemberMatt34229-Dec-06 15:16 
QuestionASP.Net environment PinmemberFranck Quintana26-Oct-06 8:24 
AnswerRe: ASP.Net environment Pinmemberdooskoobi26-Oct-06 11:51 
GeneralRe: ASP.Net environment PinmemberFranck Quintana27-Oct-06 16:27 
GeneralRe: ASP.Net environment Pinmembergedw9927-May-07 7:36 
GeneralRe: ASP.Net environment PinmemberFranck Quintana28-May-07 0:24 
GeneralRe: ASP.Net environment PinmemberDmitryKirsanov12-Oct-11 11:24 
GeneralFixed blank image [modified] PinmemberRandall Stephens16-Oct-06 7:13 
I don't know why it works, but I found a way to fix the blank image issue. It probably isn't the cleanest code, but it's available at the following link:

http://www.surpluscode.com/2006/10/16/update-web-page-thumbnail-maker/

Basically, I have a form with the web browser control in it. Before I take a screen shot, I activate that form, re-activate the main form, and then perform the screen shot work. Also, I have another form and another web browser control that takes "blank" screen shots. If the screen shot from a actual web site matches the blank screen shot (bad), the code will re-try it for up to 5 times to get a real screen shot. Usually it only takes one or two tries to get it.

I would give exact details on where to make the changes, but as you can see from the link above, I have made some significant changes to the UI and code structure.
GeneralRe: Fixed blank image [modified] PinmemberNutSoft16-Nov-06 2:37 
GeneralBlank Image Pinmembersides_dale8-Sep-06 17:32 
GeneralRe: Blank Image Pinmemberdooskoobi9-Sep-06 13:23 
GeneralRe: Blank Image PinmemberNoah Nadeau4-Apr-08 6:51 
GeneralRe: re "I can write history:" PinmemberBillWoodruff26-Aug-06 1:59 
GeneralNice find PinmemberSimone Busoli23-Aug-06 7:58 
GeneralRe: Nice find Pinmemberdooskoobi24-Aug-06 9:49 
GeneralNice, but I've got a problem PinmemberDario Solera18-Aug-06 8:47 
GeneralRe: Nice, but I've got a problem Pinmemberdooskoobi18-Aug-06 10:17 
GeneralRe: Nice, but I've got a problem PinmemberDario Solera18-Aug-06 11:19 
GeneralVery good! PinmemberDan Letecky18-Aug-06 6:29 
GeneralgetSizedImage() replacement, with better rendering Pinmemberaxelriet17-Aug-06 14:10 
GeneralRe: getSizedImage() replacement, with better rendering [modified] Pinmemberdooskoobi18-Aug-06 8:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.5 | Last Updated 17 Aug 2006
Article Copyright 2006 by dooskoobi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid