What's Here?
- Members: 306,849
- Replies: 841,330
- Topics: 140,572
- Snippets: 4,465
- Tutorials: 1,166
- Total Online: 1,666
- Members: 126
- Guests: 1,540
|
|
Submitted By: gabehabe
|
|
Rating:
 
|
|
Views: 4,315 |
Language: C#
|
|
Last Modified: September 24, 2008 |
Snippet
/*
* Author: Danny Battison
* Contact: gabehabe@googlemail.com
*/
/// <summary>
/// A method to capture a webpage as a System.Drawing.Bitmap
/// </summary>
/// <param name="URL">The URL of the webpage to capture</param>
/// <returns>A System.Drawing.Bitmap of the entire page</returns>
public System.Drawing.Bitmap CaptureWebPage(string URL)
{
// create a hidden web browser, which will navigate to the page
System. Windows. Forms. WebBrowser web = new System. Windows. Forms. WebBrowser();
web.ScrollBarsEnabled = false; // we don't want scrollbars on our image
web.ScriptErrorsSuppressed = true; // don't let any errors shine through
web.Navigate(URL); // let's load up that page!
// wait until the page is fully loaded
while (web.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(1500); // allow time for page scripts to update
// the appearance of the page
// set the size of our web browser to be the same size as the page
int width = web.Document.Body.ScrollRectangle.Width;
int height = web.Document.Body.ScrollRectangle.Height;
web.Width = width;
web.Height = height;
// a bitmap that we will draw to
System. Drawing. Bitmap bmp = new System. Drawing. Bitmap(width, height );
// draw the web browser to the bitmap
web. DrawToBitmap(bmp, new System. Drawing. Rectangle(0, 0, width, height ));
return bmp; // return the bitmap for processing
}
Copy & Paste
|
|
|
|