zoukankan
html css js c++ java
C# 截取webBrowser网页存为图片
代码
Code
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Text;
4
using
System.Data;
5
using
System.Windows.Forms;
6
using
System.Drawing;
7
8
namespace
EcsinoBrowser.Common
9
{
10
/**/
///
<summary>
11
///
WebSnap :网页抓图对象
12
///
</summary>
13
public
class
WebSnap
14
{
15
public
WebSnap()
16
{
17
//
18
//
TODO: 在此处添加构造函数逻辑
//
19
}
20
21
/**/
///
<summary>
22
///
开始一个抓图并返回图象
23
///
</summary>
24
///
<param name="Url">
要抓取的网页地址
</param>
25
///
<returns></returns>
26
public
Bitmap StartSnap(
string
Url)
27
{
28
WebBrowser myWB
=
this
.GetPage(Url);
29
Bitmap returnValue
=
this
.SnapWeb(myWB);
30
myWB.Dispose();
31
return
returnValue;
32
}
33
34
private
WebBrowser GetPage(
string
Url)
35
{
36
WebBrowser myWB
=
new
WebBrowser();
37
myWB.ScrollBarsEnabled
=
false
;
38
myWB.Navigate(Url);
39
while
(myWB.ReadyState
!=
WebBrowserReadyState.Complete)
40
{
41
System.Windows.Forms.Application.DoEvents();
42
}
43
return
myWB;
44
}
45
46
private
Bitmap SnapWeb(WebBrowser wb)
47
{
48
HtmlDocument hd
=
wb.Document;
49
int
height
=
Convert.ToInt32(hd.Body.GetAttribute(
"
scrollHeight
"
))
+
10
;
50
int
width
=
Convert.ToInt32(hd.Body.GetAttribute(
"
scrollWidth
"
))
+
10
;
51
wb.Height
=
height;
52
wb.Width
=
width;
53
Bitmap bmp
=
new
Bitmap(width, height);
54
Rectangle rec
=
new
Rectangle();
55
rec.Width
=
width;
56
rec.Height
=
height;
57
wb.DrawToBitmap(bmp, rec);
58
return
bmp;
59
}
60
}
61
}
62
代码使用
Code
1
Common.WebSnap websnap
=
new
EcsinoBrowser.Common.WebSnap();
2
Bitmap bmp
=
websnap.StartSnap(webBrowser1.Url.ToString());
3
bmp.Save(Application.StartupPath
+
@"
\crl.jpg
"
);
4
bmp.Dispose();
查看全文
相关阅读:
okhttp进行网络传输文件
bazel、tensorflow_serving、opencv编译问题
Linux下设置和查看环境变量(转)
std::move的实际工作过程
虚拷贝
移动构造函数和移动赋值
while(cin>>word)时的结束方法
转:windows下命令行工具
eclipse大括号高亮显示---颜色很淡,改为显眼的颜色
转: Eclipse 分屏显示同一个文件
原文地址:https://www.cnblogs.com/haver/p/1432475.html
最新文章
golang中最大协程数的限制(线程)
Redis 4.0.10 文档(分布式锁)
Redis 实现限流的三种方式
Redis 漏斗限流 (redis-cell)
python分布式环境下的限流器
架构设计之「服务限流」
Ocelot + Consul实践
服务器主机上RAID Card的Write Caching Policy
为什么Domain controller上的time synchronization非常重要?
小杂记
热门文章
记一个使用Client Object Model上传文件的小例子
什么是vBlock
如何在Windows Server 2012 R2上安装SharePoint 2013
如何对exec sp_who2的结果进行选择和排序?
讨论一下TaskManager中监控磁盘性能的一些小问题
为运行SQL Server的虚拟机切换装有DB Logs的最佳实践
虚机启动失败-Event 1069
Android Bitmap与String互转(转)
ubuntu移植jsoncpp到Android平台(转)
cannot use 'throw' with exceptions disabled(转)
Copyright © 2011-2022 走看看