Asp. Net:
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Namespace WindowsFormsApplication1
{
Public partial class Form1: Form
{
Private WebBrowser _ webBrowser;
Public Form1 ()
{
InitializeComponent ();
}
Public void GetThumbNail (string url)
{
_ WebBrowser = new WebBrowser ();
_ WebBrowser. ScrollBarsEnabled = false; // No scroll bar is displayed.
_ WebBrowser. Navigate (url );
_ WebBrowser. DocumentCompleted = new WebBrowserDocumentCompletedEventHandler (Completed );
While (_ webBrowser. ReadyState! = WebBrowserReadyState. Complete)
{
System. Windows. Forms. Application. DoEvents (); // prevents false positives. If this parameter is removed, the DocumentCompleted event may not be triggered.
}
}
Public void Completed (object sender, WebBrowserDocumentCompletedEventArgs e)
{
// Set the width and height of the browser to the width and height of the document to capture the entire webpage.
_ WebBrowser. Width = _ webBrowser. Document. Body. ScrollRectangle. Width;
_ WebBrowser. Height = _ webBrowser. Document. Body. ScrollRectangle. Height;
Using (Bitmap bmp = new Bitmap (_ webBrowser. Width, _ webBrowser. Height ))
{
_ WebBrowser. DrawToBitmap (bmp, new Rectangle (0, 0, bmp. Width, bmp. Height ));
Bmp. Save ("Capture.png", System. Drawing. Imaging. ImageFormat. Png );
PictureBox1.ImageLocation = "Capture.png ";
}
}
Private void button#click (object sender, EventArgs e)
{
GetThumbNail (textBox1.Text );
}
}
}