当前位置:网站首页>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);
}
}
}
}
}
}
}
边栏推荐
- Minecraft module service opening
- Simple implementation scheme of transcoding and streaming (I)
- HackTheBox-Gunship
- Minecraft群組服開服
- Openshift deployment application
- Realization of basic function of sequence table
- Hcia - Application Layer
- Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)
- 2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers
- Comparable,Comparator,Clonable 接口使用剖析
猜你喜欢

Kubedm deploys kubernetes v1.23.5 cluster

Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel

Luogu greedy part of the backpack line segment covers the queue to receive water

Sqli labs (post type injection)

What is SQL injection

kubernetes部署loki日志系统

Data asset management function

Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away

Rotating linked list (illustration)

commands out of sync. did you run multiple statements at once
随机推荐
Hcia - Application Layer
Linux安装Oracle Database 19c RAC
Getting started with k8s: building MySQL with Helm
Loadbalancer dynamically refreshes Nacos server
How to apply for a secondary domain name?
Honeypot attack and defense drill landing application scheme
ICMP Protocol
Jumping | Blue Bridge Cup
Solid principle: explanation and examples
Minecraft群組服開服
OpenFeign 简单使用
Aneng logistics' share price hit a new low: the market value evaporated by nearly 10 billion yuan, and it's useless for chairman Wang Yongjun to increase his holdings
Kubernetes deploys Loki logging system
Nacos download, start and configure MySQL database
What is SQL injection
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
IP协议与IP地址
路由基础—动态路由
k8s入门:Helm 构建 MySQL
Programming ape learning English - imperative programming