Asp. Net

Source: Internet
Author: User

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 );
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.