当前位置:网站首页>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);
}
}
}
}
}
}
}
边栏推荐
- Sentinel 简单使用
- gocv边界填充
- Kubernetes deploys Loki logging system
- Gateway is easy to use
- Tensorflow2 keras classification model
- Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
- Rotating linked list (illustration)
- Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
- Nacos 下载启动、配置 MySQL 数据库
- kubernetes部署loki日志系统
猜你喜欢

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

ARP及ARP欺骗

Sqli labs Level 2

c语言将字符串中的空格替换成%20

Linux二进制安装Oracle Database 19c

Installing Oracle database 19C RAC on Linux

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

KubeSphere 虚拟化 KSV 安装体验

整理秒杀系统的面试必备!!!

Nacos download, start and configure MySQL database
随机推荐
群辉 NAS 配置 iSCSI 存储
Learning C
Linux安装Oracle Database 19c RAC
web安全--逻辑越权
使用递归函数求解字符串的逆置问题
Programming ape learning English - imperative programming
HCIA - application layer
Finishing the interview essentials of secsha system!!!
Tcp/ip - transport layer
Analysis of the use of comparable, comparator and clonable interfaces
顺序表基本功能函数的实现
Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
File upload and download performance test based on the locust framework
随笔:RGB图像颜色分离(附代码)
Nacos 下载启动、配置 MySQL 数据库
PCL calculates the intersection of three mutually nonparallel planes
Sentinel easy to use
文件上传-upload-labs
HCIA—應用層