当前位置:网站首页>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);
}
}
}
}
}
}
}
边栏推荐
- idea中注释代码取消代码的快捷键
- Openfeign facile à utiliser
- 一、Qt的核心类QObject
- Makefile基本原理
- Rotating linked list (illustration)
- Loadbalancer dynamically refreshes Nacos server
- 汉诺塔问题的求解与分析
- [flask] ORM one-to-one relationship
- ICMP Protocol
- C language custom types - structure, bit segment (anonymous structure, self reference of structure, memory alignment of structure)
猜你喜欢

Analysis of the use of comparable, comparator and clonable interfaces

OpenFeign 简单使用

Sentinel easy to use

Sqli labs (post type injection)

顺序表基本功能函数的实现

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

Qunhui NAS configuring iSCSI storage

旋转链表(图解说明)

方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
![[blackmail virus data recovery] suffix Rook3 blackmail virus](/img/46/debc848d17767d021f3f41924cccfe.jpg)
[blackmail virus data recovery] suffix Rook3 blackmail virus
随机推荐
Googlenet network explanation and model building
[untitled]
程序猿学英语-指令式编程
c语言自定义类型——结构体,位段(匿名结构体,结构体的自引用,结构体的内存对齐)
HackTheBox-Gunship
2022 Heilongjiang latest construction eight members (materialman) simulated examination questions and answers
What are the platforms for selling green label domain names? What is the green label domain name like?
Realize bidirectional linked list (with puppet node)
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
2022 Heilongjiang's latest eight member (Safety Officer) simulated test question bank and answers
gocv图片裁剪并展示
Sqli labs Level 2
Sqli labs level 1
Use the kaggle training model and download your own training model
Nacos 下载启动、配置 MySQL 数据库
k8s入门:Helm 构建 MySQL
Simple implementation scheme of transcoding and streaming (I)
Use Wireshark to grab TCP three handshakes
Openshift deployment application
Minecraft模组服开服