I was recently tinkering around in an admin tool that is used to build web-sites, and found myself wondering if it was possible to create a "preview" of the web-site as an image. The idea being, I want to show a list of pages in the website with thumbnails of page previews; thus the site administrator can see the entire site on a single page and would be able to know what they were editing before they opened the page configuration.
If you're like me, these kinds of problems drive me crazy. I ear mark them as "nifty ideas" and I slowly mull them over in my head when my head has idle time. (What, you don't have head idle time? Between 3-4 in the morning when I change sleeping positions, I have to force myself not to address my mental challenge To-do list. I recently discovered that our brains solve a lot of problems after only a few hours of sleep.)
So although I haven't actually cracked the code open to tackle this problem, here's what I envision the implementation to be:
- Use the .NET Process object to launch a window to the web page.
- Grab the handle of the Process and pass it to the GDI+ to convert into an image. This CodeProject article gives a really good overview of doing just that.
I'm hoping that if the .NET Process is launched with the ProcessWindowStyle set to "Hidden" that it still has a valid device context used to paint onto the screen. If that's true, there should be no reason why I couldn't convert the hidden window's content into a Bitmap.
Few other things to consider, such as when to determine that the browser has fully loaded the requested page? I might have to consider using the WebBrowser control to load the webpage and wait until the document onload event or page status changes....
Yet another task to play with...