当前位置:网站首页>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);
}
}
}
}
}
}
}
边栏推荐
- OpenFeign 簡單使用
- C language replaces spaces in strings with%20
- Programming ape learning English - imperative programming
- 程序猿学英语-指令式编程
- 旋转链表(图解说明)
- Zipkin is easy to use
- 类和对象(类和类的实例化,this,static关键字,封装)
- Illegal use of crawlers, an Internet company was terminated, the police came to the door, and 23 people were taken away
- Luogu greedy part of the backpack line segment covers the queue to receive water
- web安全--逻辑越权
猜你喜欢
Installing Oracle database 19C for Linux
C language custom types - structure, bit segment (anonymous structure, self reference of structure, memory alignment of structure)
k8s入门:Helm 构建 MySQL
Openshift deployment application
OpenShift构建镜像
[blackmail virus data recovery] suffix Hydra blackmail virus
什么是SQL注入
Openfeign facile à utiliser
Luogu greedy part of the backpack line segment covers the queue to receive water
路由基础—动态路由
随机推荐
STM32 new project (refer to punctual atom)
Minecraft install resource pack
OpenShift 部署应用
Kubedm deploys kubernetes v1.23.5 cluster
Routing foundation - dynamic routing
Linux安装Oracle Database 19c RAC
Learning C
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
Qt的右键菜单
Web security -- Logical ultra vires
图像变换,转置
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
Realize bidirectional linked list (with puppet node)
统计字符串中各类字符的个数
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
First week of JS study
OpenShift构建镜像
gocv opencv exit status 3221225785
C language custom type enumeration, Union (clever use of enumeration, calculation of union size)
Qunhui NAS configuring iSCSI storage