码迷,mamicode.com
首页 > Web开发 > 详细

asp.net 截屏

时间:2017-09-16 15:59:41      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:control   system   oev   无法   form   using   capture   cat   高度   

  public class HomeController : Controller
    {
        //
        // GET: /Home/
        static System.Windows.Forms.WebBrowser wb;
      
        public void ScreenCapture()
        {
            System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(() =>
            {
                wb = new System.Windows.Forms.WebBrowser();
                wb.DocumentCompleted += wb_DocumentCompleted;
                wb.Navigate("https://www.baidu.com/");
                while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete)
                {
                    System.Windows.Forms.Application.DoEvents(); //避免假死,若去掉则可能无法触发 DocumentCompleted 事件。
                }
            })
            );
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
        void wb_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
        {
            //设置浏览器宽度、高度为文档宽度、高度,以便截取整个网页。
            //wb.Width = wb.Document.Body.ScrollRectangle.Width;
            //wb.Height = wb.Document.Body.ScrollRectangle.Height;
            wb.Width = 1366;
            wb.Height = wb.Document.Body.ScrollRectangle.Height;
            using (Bitmap bmp = new Bitmap(wb.Width, wb.Height))
            {
                wb.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
                bmp.Save("C:\\Capture1.png", ImageFormat.Png);
            }
        }
    }

 

asp.net 截屏

标签:control   system   oev   无法   form   using   capture   cat   高度   

原文地址:http://www.cnblogs.com/gaocong/p/7531370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!