熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

Asp.Net獲取網站截圖的實例代碼

2022-06-13   來源: .NET編程 
這篇文章介紹了AspNet獲取網站截圖的實例代碼有需要的朋友可以參考一下   復制代碼 代碼如下:

  
using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
namespace WindowsFormsApplication
{
    public partial class Form : Form
    {
        private WebBrowser _webBrowser;
        public Form()
        {
            InitializeComponent();
        }
        public void GetThumbNail(string url)
        {
            _webBrowser = new WebBrowser();
            _webBrowserScrollBarsEnabled = false; //不顯示滾動條
            _webBrowserNavigate(url);
            _webBrowserDocumentCompleted = new WebBrowserDocumentCompletedEventHandler(Completed);
            while (_webBrowserReadyState != WebBrowserReadyStateComplete)
            {
                SystemWindowsFormsApplicationDoEvents(); //避免假死若去掉則可能無法觸發 DocumentCompleted 事件
            }
        }
        public void Completed(object sender WebBrowserDocumentCompletedEventArgs e)
        {
            //設置浏覽器寬度高度為文檔寬度高度以便截取整個網頁
            _webBrowserWidth = _webBrowserDocumentBodyScrollRectangleWidth;
            _webBrowserHeight = _webBrowserDocumentBodyScrollRectangleHeight;
            using (Bitmap bmp = new Bitmap(_webBrowserWidth _webBrowserHeight))
            {
                _webBrowserDrawToBitmap(bmp new Rectangle( bmpWidth bmpHeight));
                bmpSave("Capturepng" SystemDrawingImagingImageFormatPng);
                pictureBoxImageLocation = "Capturepng";
            }
        }
        private void button_Click(object sender EventArgs e)
        {
            GetThumbNail(textBoxText);
        }
    }
}


From:http://tw.wingwit.com/Article/program/net/201311/14407.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.