新聞中心
今天就跟大家聊聊有關(guān)怎么在Asp.Net項(xiàng)目中實(shí)現(xiàn)一個獲取網(wǎng)站截圖功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
復(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; //不顯示滾動條
_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è)置瀏覽器寬度、高度為文檔寬度、高度,以便截取整個網(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);
}
}
}
看完上述內(nèi)容,你們對怎么在Asp.Net項(xiàng)目中實(shí)現(xiàn)一個獲取網(wǎng)站截圖功能有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
網(wǎng)頁標(biāo)題:怎么在Asp.Net項(xiàng)目中實(shí)現(xiàn)一個獲取網(wǎng)站截圖功能-創(chuàng)新互聯(lián)
本文URL:http://ef60e0e.cn/article/codejd.html