手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >Asp.Net获取网站截图的实例代码
Asp.Net获取网站截图的实例代码
摘要:复制代码代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Compo...

复制代码 代码如下:

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);

}

}

}

【Asp.Net获取网站截图的实例代码】相关文章:

ASP.NET中高质量缩略图的生成代码

.net获取本机公网IP地址示例

asp.net中利用Jquery+Ajax+Json实现无刷新分页的实例代码

asp.net web大文件上传带进度条实例代码

asp.net微软图表控件使用示例代码分享

asp.net网站首页根据IP自动跳转指定页面的示例

asp.net图片上传生成缩略图的注意事项

asp.net(C#)生成Code39条形码实例

asp.net 生成曲线图实现代码

Asp.Net Cache缓存使用代码

精品推荐
分类导航