您现在的位置是:网站首页> 编程资料编程资料
Asp.Net获取网站截图的实例代码_实用技巧_
2023-05-25
384人已围观
简介 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);
}
}
}
相关内容
- asp.net实现上传文件显示本地绝对路径的实例代码_实用技巧_
- ASP.NET连接SQL数据库的简单实例代码_实用技巧_
- Asp.Net上传图片验证代码的小例子_实用技巧_
- 详解ASP.NET页面生命周期事件_实用技巧_
- .net输出重写压缩页面文件的小例子_实用技巧_
- 一个ASP.Net下的WebShell实例_实用技巧_
- .Net中生成二维的表格的代码 分享_实用技巧_
- asp.net 将一个图片以二进制值的形式存入Xml文件中的实例代码_实用技巧_
- .Net 下区别使用 ByRef/ByVal 的重要性 分享_实用技巧_
- VB.NET拷贝整个目录下所有子目录及文件的实例代码_实用技巧_
