. - C#, .Net Framework" /> Topicala Page Index Token

A Journal about the experiences I have developing little applications in C#, Perl, Html and Javascript and talking about things new things that I use. Always Geeky; Always Nerdy; Always poor Grammer!

I am a Software Analyst Developer working in Southport, England but living in Liverpool. I develop mainly in C# and ASP.Net. I have been developing comercial software for several years now. I maintain this site (hosted at SwitchMedia UK) as a way of exploring new technologies (such as AJAX) and just generally talking about techie geek issues. This site is developed through a host of Perl scripts and a liberal use of Javascript. I enjoy experimenting with new technologies and anything that I make I host here.

Quick Search

Web www.kinlan.co.uk

Monday, January 29, 2007

Easy HTML Screen Capture in Windows

For a while I have been thinking about how to capture the output of IE into a Bitmap or other image format.  The attempts that I have done normally center around hosting an IE control on a WinForm and then render the page inside the control and then capture the output.  This however seems to be pretty hairy, I could never get it to work after the initial screen capture.

It just so happens that the WindowsLiveWriter API has an object called HtmlScreenCapture. 

HtmlScreenCapture is really simle to use.  The code below captures the webpage and renders it to a picture box that I have on my WinForm.

Uri uri = new Uri("http://www.kinlan.co.uk/");

WindowsLive.Writer.Api.HtmlScreenCapture hsc = new HtmlScreenCapture(uri, 800);
pictureBox1.Image = hsc.CaptureHtml(1000);

You can import the WindowsLiveWriter API into your project by finding the WindowsLive.Writer.Api.dll file in the WindowsLiveWriter install directory.

Obviously, WindowsLiveWriter is still beta as of Jan 2007, so they may remove this API.

Anyway it is really simple to use, so anyone could create an imaging service in minutes, much like http://www.websnapr.com/ can.


Comments: [Add New]

I cant get it to work as a .NET generic handler!

Have you tested it in a we application or are you just assuming it will work in a web app?

By Anonymous Anonymous, at Wednesday, February 21, 2007 3:55:00 AM


When I was thinking about how I would do this, i didn't want to put it in a HTTP Handler to handle on WebRequests comming into my server.

Rather, I was going to create a Windows Service that read a database of screen shots that it had to generate, and put it in a place where the webserver can get to it.

Kind Regards,
Paul Kinlan

By Blogger Paul Kinlan, at Wednesday, February 21, 2007 8:11:00 AM

Anyone figure out why this does not work in the context of IIS 7 + vista? On know the security model is different but I would really like to use this API. Specfically I would really like to use the constructor that takes in the HTML directly instead of the Uri but this always generates and exception.


By Blogger Will, at Friday, October 26, 2007 10:33:00 PM

Thanks for the tip! Works great.

By Anonymous Anonymous, at Wednesday, August 06, 2008 9:42:00 AM

I really like this approach - very cool!

The one problem that I see is that the content width is hard to define. I was thinking about trying to automatically crop it, but that seems like it might have some issues. Did you discover a good way to determine the correct screen width for a given page?

By Blogger Erick T, at Friday, June 19, 2009 10:43:00 PM

To capture html or website page as image I use WebsitesScreenshot DLL . This .net dll is easy to use in any .net language.

By Anonymous Farhomar, at Friday, December 04, 2009 1:15:00 PM