Asp.Net获取网站截图的实例代码
2023-06-13 09:15:03 时间
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceWindowsFormsApplication1
{
publicpartialclassForm1:Form
{
privateWebBrowser_webBrowser;
publicForm1()
{
InitializeComponent();
}
publicvoidGetThumbNail(stringurl)
{
_webBrowser=newWebBrowser();
_webBrowser.ScrollBarsEnabled=false;//不显示滚动条
_webBrowser.Navigate(url);
_webBrowser.DocumentCompleted=newWebBrowserDocumentCompletedEventHandler(Completed);
while(_webBrowser.ReadyState!=WebBrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();//避免假死,若去掉则可能无法触发DocumentCompleted事件。
}
}
publicvoidCompleted(objectsender,WebBrowserDocumentCompletedEventArgse)
{
//设置浏览器宽度、高度为文档宽度、高度,以便截取整个网页。
_webBrowser.Width=_webBrowser.Document.Body.ScrollRectangle.Width;
_webBrowser.Height=_webBrowser.Document.Body.ScrollRectangle.Height;
using(Bitmapbmp=newBitmap(_webBrowser.Width,_webBrowser.Height))
{
_webBrowser.DrawToBitmap(bmp,newRectangle(0,0,bmp.Width,bmp.Height));
bmp.Save("Capture.png",System.Drawing.Imaging.ImageFormat.Png);
pictureBox1.ImageLocation="Capture.png";
}
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
GetThumbNail(textBox1.Text);
}
}
}
相关文章
- .net 温故知新:【8】.NET 中的配置从xml转向json
- 《ASP.NET Core 6框架揭秘》实例演示:自定义一个服务器
- ASP.NET和MSSQL高性能分页实例代码
- .net安装 Linux 上的 ASP.NET 环境(linux安装asp)
- 用ASP搭建MySQL网站技术实例(asp mysql 网站)
- 用Net和MySQL实现软件开发编程(.net mysql编程)
- asp.net下配置数据源时出现:未将对象引用设置到对象的实例。
- Asp.net在三层架构中事务的使用实例代码
- asp.net中文件下载功能的实例代码
- 在ASP.NET中插入flash代码实例
- KindEditor图片上传的Asp.net代码实例
- ASP.NET实现TreeView的XML数据源绑定实例代码
- Asp.Net(C#)自动执行计划任务的程序实例分析分享
- asp.net各种cookie代码和解析实例
- ASP.NET中XML转JSON的方法实例
- .Net基于MVC4WebApi输出Json格式实例
- asp.net中生成饼状与柱状图实例
- asp.net源程序编译为dll文件并调用的实现过程
- .NET下文本相似度算法余弦定理和SimHash浅析及应用实例分析
- 四个常用的.NET的SQLHELPER方法实例