asp.net 截屏 截取web页面
1 using System.Drawing; 2 3 //调用浏览器打开页面 4 System.Diagnostics.Process.Start("IEXPLORE.EXE", "http://localhost:56/Spacxxe.html"); 5 //停止3秒,等页面打开 6 System.Threading.Thread.Sleep(3000); 7 8 //截屏 9 //创建并设置画布大小 10 System.Drawing.Image templateImage = new System.Drawing.Bitmap(1040, 700); 11 System.Drawing.Graphics templateG = System.Drawing.Graphics.FromImage(templateImage); 12 13 //new Point(200, 100)位于源(屏幕)左上角的x,y坐标 14 //new Point(0, 0)图片位于画布左上角的x,y坐标 15 //new Size(1440, 900)所截屏幕的大小 16 templateG.CopyFromScreen(new Point(200, 100), new Point(0, 0), new Size(1000, 900), CopyPixelOperation.MergeCopy); 17 18 //关闭ie 19 System.Diagnostics.Process[] pro = System.Diagnostics.Process.GetProcessesByName("IEXPLORE"); 20 foreach (System.Diagnostics.Process ps in pro) 21 { 22 ps.Kill(); 23 } 24 25 //存图片 26 templateImage.Save(@"E:\TEST\" + imgname + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
截图过程,是通过aps.net 页面调用ie浏览器进程打开页面,并且调用CopyFromScreen来截屏并保存。