asp.net get the screenshot of the site instance code _ Practical Tips

Source: Internet
Author: User
Copy Code code as follows:

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; Do not show scroll bars
_webbrowser.navigate (URL);
_webbrowser.documentcompleted = new Webbrowserdocumentcompletedeventhandler (Completed);
while (_webbrowser.readystate!= webbrowserreadystate.complete)
{
System.Windows.Forms.Application.DoEvents (); Avoid suspended animation, if removed may not trigger the DocumentCompleted event.
}
}
public void Completed (object sender, WebBrowserDocumentCompletedEventArgs e)
{
Sets the browser width, height to document width, and height to intercept the entire Web page.
_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 Button1_Click (object sender, EventArgs e)
{
GetThumbnail (TextBox1.Text);
}
}
}

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.