当前位置:网站首页>C# 将网页保存为图片(利用WebBrowser)
C# 将网页保存为图片(利用WebBrowser)
2022-07-02 06:32:00 【清山博客】
using System;
using System.Drawing;
using System.Windows.Forms;
namespace UrlToImage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var browser = new WebBrowser {ScrollBarsEnabled = false, ScriptErrorsSuppressed = true};
browser.Navigate("http://www.rc114.com/");
browser.DocumentCompleted += webBrowser_DocumentCompleted;
}
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var browser = (WebBrowser) sender;
if (browser.ReadyState == WebBrowserReadyState.Complete)
{
if (browser.Document != null)
{
if (browser.Document.Body != null)
{
var height = browser.Document.Body.ScrollRectangle.Height;
var width = browser.Document.Body.ScrollRectangle.Width;
browser.Height = height;
browser.Width = width;
using (var bitmap = new Bitmap(width, height))
{
var rectangle = new Rectangle(0, 0, width, height);
browser.DrawToBitmap(bitmap, rectangle);
var dialog = new SaveFileDialog();
dialog.Filter = " JPEG (*.jpg)|*.jpg|PNG (*.png)|*.png ";
dialog.ShowDialog();
bitmap.Save(dialog.FileName);
}
}
}
}
}
}
}
边栏推荐
- 双向链表的实现(双向链表与单向链表的简单区别联系和实现)
- How to apply for a secondary domain name?
- ARP and ARP Spoofing
- Sentinel 简单使用
- 用数字 5,5,5,1 ,进行四则运算,每个数字当且仅当用一次,要求运算结果值为 24
- Dip1000 implicitly tagged with fields
- Programming ape learning English - imperative programming
- 整理秒杀系统的面试必备!!!
- The best blog to explain the basics of compilation (share)
- sqli-labs第2关
猜你喜欢

TCP/IP—传输层

Minecraft模组服开服

Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)

Linux安装Oracle Database 19c RAC

sqli-labs第2关

OpenShift构建镜像

sqli-labs第8关(布尔盲注)

Solid principle: explanation and examples

C language custom types - structure, bit segment (anonymous structure, self reference of structure, memory alignment of structure)

Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
随机推荐
Solid principle: explanation and examples
Network security - summary and thinking of easy-to-use fuzzy tester
Sqli labs level 1
HackTheBox-Gunship
web安全--逻辑越权
Web security -- core defense mechanism
sqli-labs第1关
ARP及ARP欺骗
How to apply for a secondary domain name?
Gateway 简单使用
C language custom type enumeration, Union (clever use of enumeration, calculation of union size)
Minecraft install resource pack
Kubesphere virtualization KSV installation experience
[blackmail virus data recovery] suffix Crylock blackmail virus
PCL calculates the intersection of three mutually nonparallel planes
gocv拆分颜色通道
ARP and ARP Spoofing
ICMP协议
Comparable,Comparator,Clonable 接口使用剖析
IP协议与IP地址