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目录下
}
}