Asp.Net獲取網(wǎng)站截圖的實例代碼
更新時間:2013年07月25日 10:50:25 作者:
這篇文章介紹了Asp.Net獲取網(wǎng)站截圖的實例代碼,有需要的朋友可以參考一下
復(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);
}
}
}
相關(guān)文章
asp.net GridView 刪除時彈出確認(rèn)對話框(包括內(nèi)容提示)
GridView 刪除時彈出確認(rèn)對話框(包括內(nèi)容提示)2009-12-12win2003服務(wù)器asp.net權(quán)限設(shè)置問題及解決方法
ASP.NET相對于ASP,設(shè)置權(quán)限方面有點不同,有一點兒設(shè)置錯了都運(yùn)行不到。在網(wǎng)上搜索到的都是很垃圾的答案,沒有一個用得到的,下面是我自己設(shè)置并從中遇到的問題摸索后得到的經(jīng)驗,給大家分享。2011-08-08Visual Studio Debug實戰(zhàn)教程之?dāng)帱c操作
眾所周知斷點對于Visual Studio調(diào)試過程是十分重要的,斷點的設(shè)置也是為了更好的進(jìn)行調(diào)試。下面這篇文章主要給大家介紹了關(guān)于Visual Studio Debug實戰(zhàn)教程之?dāng)帱c操作的相關(guān)資料,需要的朋友可以參考下2018-09-09asp.net(c#)有關(guān) Session 操作的幾個誤區(qū)
asp.net(c#)有關(guān) Session 操作的幾個誤區(qū)...2007-06-06ASP.NET?Core?使用SignalR推送服務(wù)器日志的過程記錄
這篇文章主要介紹了ASP.NET?Core?使用SignalR推送服務(wù)器日志的相關(guān)知識,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-01-01asp.net ext treepanel 動態(tài)加載XML的實現(xiàn)方法
當(dāng)你在asp.net下面 使用Ext TreePanel直接加載服務(wù)器上XML文件會出現(xiàn)樹不能顯示,樹據(jù)不能正確加載的問題。2008-10-10