华域联盟 .Net Asp.Net获取网站截图的实例代码

Asp.Net获取网站截图的实例代码

复制代码 代码如下:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        private WebBrowser _webBrowser;

        public Form1()

        {

            InitializeComponent();

        }

        public void GetThumbNail(string url)

        {

            _webBrowser = new WebBrowser();

            _webBrowser.ScrollBarsEnabled = false; //不显示滚动条

            _webBrowser.Navigate(url);

            _webBrowser.DocumentCompleted = new WebBrowserDocumentCompletedEventHandler(Completed);

            while (_webBrowser.ReadyState != WebBrowserReadyState.Complete)

            {

                System.Windows.Forms.Application.DoEvents(); //避免假死,若去掉则可能无法触发 DocumentCompleted 事件。

            }

        }

        public void Completed(object sender, WebBrowserDocumentCompletedEventArgs e)

        {

            //设置浏览器宽度、高度为文档宽度、高度,以便截取整个网页。

            _webBrowser.Width = _webBrowser.Document.Body.ScrollRectangle.Width;

            _webBrowser.Height = _webBrowser.Document.Body.ScrollRectangle.Height;

            using (Bitmap bmp = new Bitmap(_webBrowser.Width, _webBrowser.Height))

            {

                _webBrowser.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));

                bmp.Save("Capture.png", System.Drawing.Imaging.ImageFormat.Png);

                pictureBox1.ImageLocation = "Capture.png";

            }

        }

        private void button1_Click(object sender, EventArgs e)

        {

            GetThumbNail(textBox1.Text);

        }

    }

}
您可能感兴趣的文章:

  • jQuery jcrop插件截图使用方法
  • jcrop 网页截图工具(插件)开发
  • asp.net截屏功能实现截取web页面
  • js插件Jcrop自定义截取图片功能

本文由 华域联盟 原创撰写:华域联盟 » Asp.Net获取网站截图的实例代码

转载请保留出处和原文链接:https://www.cnhackhy.com/51304.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部