欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Asp.Net獲取網(wǎng)站截圖的實(shí)例代碼

 更新時(shí)間:2013年07月25日 10:50:25   作者:  
這篇文章介紹了Asp.Net獲取網(wǎng)站截圖的實(shí)例代碼,有需要的朋友可以參考一下
復(fù)制代碼 代碼如下:

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; //不顯示滾動(dòng)條
            _webBrowser.Navigate(url);
            _webBrowser.DocumentCompleted = new WebBrowserDocumentCompletedEventHandler(Completed);
            while (_webBrowser.ReadyState != WebBrowserReadyState.Complete)
            {
                System.Windows.Forms.Application.DoEvents(); //避免假死,若去掉則可能無法觸發(fā) DocumentCompleted 事件。
            }
        }
        public void Completed(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //設(shè)置瀏覽器寬度、高度為文檔寬度、高度,以便截取整個(gè)網(wǎng)頁。
            _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);
        }
    }
}

相關(guān)文章

最新評(píng)論