Asp.Net获取网站截图的实例代码
更新时间:2013年07月25日 10:50:25 作者:
这篇文章介绍了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);
}
}
}
相关文章
GridView中checkbox"全选/取消"完美兼容IE和Firefox
GridView中checkbox的的"全选/取消"使用还是比较频繁的,本文有个不错的示例完美兼容IE和Firefox,感兴趣的朋友可以参考下,希望对大家有所帮助2013-10-10
asp.net ajaxControlToolkit FilteredTextBoxExtender的简单用法
最近写的东西验证比较多,尤其是数字验证,无意中发现这个控件,有点儿意思。记录一下2008-11-11
解决VS2012 Express的There was a problem sending the command to
安装Visual Studio 2012 Express之后,双击打开web.config文件时经常出现“There was a problem sending the command to the program”的错误,然后VS2012 Express打开了,但web.config文件没打开,需要再次双击web.config文件才能打开。很是烦人2013-02-02


最新评论