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();
查看全文
相关阅读:
Lua 有关字符串的剪切 以及匹配
[Decode error
mac 终端 常用命令
mac apache 相关终端命令
spring boot架构设计——权限验证及API接口统一返回格式
ios 官网文档翻译—Create a Table View(swift)
quicksqlite简介
android ndk 环境搭建和简单实例
android 关闭软键盘
android 弹出全局加载等待动画
原文地址:https://www.cnblogs.com/haver/p/1432475.html
最新文章
关于EnumerateObjectsUsingBlock和for-in之间的较量
解决 iOS View Controller Push/Pop 时的黑影
iOS xocde编译报错 NSObjCRuntime.h
iOS的AppDelegate方法中的事件触发调用
android.app.Notification
listview添加的有Headview后onItemClick函数获取的listView的行值有问题,点任何一行的数据,捕获的id值都为1,奇怪!
ListView.addHeaderView抛出的异常及解决方法
sqlite SQL语句
SimpleCursorAdapter参数from必须包含_id字段的原因
SimpleCursorAdapter(Context, int, Cursor, String[], int[]) is deprecated???
热门文章
Ubuntu下面有adb工具安装和卸载apk包
Android中 与数据库有关的两个废除的方法
Android使用通讯录的权限问题
ListActivity学习
Mac 下使用AS 报错 svn: E155021 当前svn 版本太低
Mac 添加java 环境变量成功后,依然会报错 错误: 找不到或无法加载主类
Mac 升级到OS X 10.11 El Capitan 后的坑--Apache
Mac下 ADT 找不到手机设备
Mac下Cornerstone无法查看SVN日志的问题的解决办法
Sublime Text2 Decode error
Copyright © 2011-2022 走看看