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();
查看全文
相关阅读:
洛谷 P3138 [USACO16FEB]Load Balancing S(二维前缀和,离散化)
洛谷 P1052 [NOIP2005 提高组] 过河(dp,数学)
洛谷 P1955 [NOI2015] 程序自动分析(并查集,离散化)
洛谷 P3258 [JLOI2014]松鼠的新家(树上差分,lca)
洛谷 P2296 [NOIP2014 提高组] 寻找道路(反图bfs)
洛谷 P4141 消失之物(dp方案数)
洛谷 P5322 [BJOI2019]排兵布阵(dp,分组背包)
回溯算法
分治法
分支限界法
原文地址:https://www.cnblogs.com/haver/p/1432475.html
最新文章
OpenShift上的路由器与Kubernetes上的Ingress
k8s ingress原理及ingress-nginx部署测试
使用ingress+service机制实现高可用负载均衡
flutter 微信支付
flutter 支付宝支付 tobias: ^1.7.1+1
flutter 要求在MaterialApp里的builder写多个东西例如:插件等
NOI2021 游记
Jupyter添加虚拟环境
炸鱼了炸鱼了
三维点云处理
热门文章
新浪微博视频批量上传社区投稿教程
新浪微博视频批量上传社区投稿哪里可以下载?
洛谷 P1725 琪露诺(单调队列优化dp)
洛谷 P3958 [NOIP2017 提高组] 奶酪(建图,dfs)
洛谷 P2216 [HAOI2007]理想的正方形(二维单调队列)
洛谷 P1950 长方形(单调栈,dp)
洛谷 P3467 [POI2008]PLA-Postering(单调栈)
AT4142 [ARC098B] Xor Sum 2(尺取法)
洛谷 P1311 [NOIP2011 提高组] 选择客栈 & P6032 选择客栈 加强版(双指针)
洛谷 P1102 A-B 数对(双指针)
Copyright © 2011-2022 走看看