当前位置:网站首页>C # save web pages as pictures (using WebBrowser)
C # save web pages as pictures (using WebBrowser)
2022-07-02 08:45:00 【Qingshan blog】
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);
}
}
}
}
}
}
}
边栏推荐
猜你喜欢

C language replaces spaces in strings with%20

Honeypot attack and defense drill landing application scheme
![[blackmail virus data recovery] suffix Crylock blackmail virus](/img/b2/8e3a65dd250b9194cfc175138c740c.jpg)
[blackmail virus data recovery] suffix Crylock blackmail virus

Linux二进制安装Oracle Database 19c

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

Qt——如何在QWidget中设置阴影效果
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Sentinel easy to use

sqli-labs第2关

Application of kotlin - higher order function
随机推荐
Luogu greedy part of the backpack line segment covers the queue to receive water
File upload Labs
zipkin 简单使用
Programming ape learning English - imperative programming
路由基础—动态路由
Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)
HCIA - application layer
判断是否是数独
OpenShift构建镜像
Openfeign is easy to use
Qt——如何在QWidget中设置阴影效果
Jumping | Blue Bridge Cup
Sqli labs (post type injection)
Comparable,Comparator,Clonable 接口使用剖析
First week of JS study
kubeadm部署kubernetes v1.23.5集群
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
Minecraft安装资源包
Detailed explanation of NIN network
Makefile基本原理