当前位置:网站首页>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);
}
}
}
}
}
}
}
边栏推荐
- 文件上传-upload-labs
- commands out of sync. did you run multiple statements at once
- Synchronize files using unison
- Introduction to anti interception technology of wechat domain name
- Flex layout
- Qt的connect函数和disconnect函数
- HCIA - application layer
- HackTheBox-Gunship
- Detailed explanation of NIN network
- Kubedm deploys kubernetes v1.23.5 cluster
猜你喜欢

Minecraft群组服开服

方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)

web安全--逻辑越权

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

File upload Labs

What is SQL injection

Flex layout

Sentinel 简单使用

sqli-labs第12关

Finishing the interview essentials of secsha system!!!
随机推荐
Dip1000 runaway
Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
sqli-labs第12关
类和对象(类和类的实例化,this,static关键字,封装)
First week of JS study
File upload and download performance test based on the locust framework
Network security - summary and thinking of easy-to-use fuzzy tester
c语言将字符串中的空格替换成%20
C language replaces spaces in strings with%20
Introduction to anti interception technology of wechat domain name
History of Web Technology
汉诺塔问题的求解与分析
Web security -- Logical ultra vires
ICMP协议
c语言自定义类型枚举,联合(枚举的巧妙使用,联合体大小的计算)
How to apply for a secondary domain name?
Googlenet network explanation and model building
web安全--逻辑越权
Openfeign is easy to use