C # webpage screenshot

Source: Internet
Author: User

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
// You need to add System. Drawing and System. Windows. Forms references.
Using System. Drawing;
Using System. Drawing. Drawing2D;
Using System. Drawing. Imaging;
Using System. Windows. Forms;

Namespace PageNumber
{
Class Program
{
[STAThread]
Static void Main (string [] args)
{
String url = "http://www.531.hk /";
GetImage thumb = new GetImage (url, 1024,768,102 4, 768 );
System. Drawing. Bitmap x = thumb. GetBitmap ();
String FileName = DateTime. Now. ToString ("yyyyMMddhhmmss ");
X. Save (@ "C:" + FileName + ". jpg ");
Console. WriteLine (@ "C:" + FileName + ". jpg saved successfully .");
Console. ReadKey ();
}

Public class GetImage
{
Private int S_Height;
Private int S_Width;
Private int F_Height;
Private int F_Width;
Private string MyURL;

Public int ScreenHeight
{
Get {return S_Height ;}
Set {S_Height = value ;}
}

Public int ScreenWidth
{
Get {return S_Width ;}
Set {S_Width = value ;}
}

Public int ImageHeight
{
Get {return F_Height ;}
Set {F_Height = value ;}
}

Public int ImageWidth
{
Get {return F_Width ;}
Set {F_Width = value ;}
}

Public string WebSite
{
Get {return MyURL ;}
Set {MyURL = value ;}
}

Public GetImage (string WebSite, int ScreenWidth, int ScreenHeight, int ImageWidth, int ImageHeight)
{
This. WebSite = WebSite;
This. ScreenWidth = ScreenWidth;
This. ScreenHeight = ScreenHeight;
This. ImageHeight = ImageHeight;
This. ImageWidth = ImageWidth;
}

Public Bitmap GetBitmap ()
{
WebPageBitmap Shot = new WebPageBitmap (this. WebSite, this. ScreenWidth, this. ScreenHeight );
Shot. GetIt ();
Bitmap Pic = Shot. DrawBitmap (this. ImageHeight, this. ImageWidth );
Return Pic;
}
}

Class WebPageBitmap
{
WebBrowser MyBrowser;
String URL;
Int Height;
Int Width;

Public WebPageBitmap (string url, int width, int height)
{
This. Height = height;
This. Width = width;
This. URL = url;
MyBrowser = new WebBrowser ();
MyBrowser. ScrollBarsEnabled = false;
MyBrowser. Size = new Size (this. Width, this. Height)

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.