Web截取网页图片

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string PhotoName = Guid.NewGuid().ToString();
        //打开该页面
        System.Diagnostics.Process.Start("IEXPLORE.EXE", "http://www.baidu.com");

        System.Threading.Thread.Sleep(3000);
        //截屏

        //创建并设置画布大小
        System.Drawing.Image templateImage = new System.Drawing.Bitmap(1040,800);
        System.Drawing.Graphics templateG = System.Drawing.Graphics.FromImage(templateImage);


        //new Point(200, 100)位于源(屏幕)左上角的x,y坐标
        //new Point(0, 0)图片位于画布左上角的x,y坐标
        //new Size(1440, 900)所截屏幕的大小
        templateG.CopyFromScreen(new Point(200, 150), new Point(0, 0), new Size(1040, 800), CopyPixelOperation.MergeCopy);

        //关闭ie
        System.Diagnostics.Process[] pro = System.Diagnostics.Process.GetProcessesByName("IEXPLORE");
        foreach (System.Diagnostics.Process ps in pro)
        {
            ps.Kill();
        }

        //存
        //templateImage.Save(@"E:\TEST\" + photoname + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
        templateImage.Save(Server.MapPath("SnapPic/" + PhotoName + ".jpg"), System.Drawing.Imaging.ImageFormat.Png);//保存截图到项目SnapPic目录下

    }
}

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. –Martin Fowler
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/gerryge/p/2241163.html