当前位置:网站首页>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);
}
}
}
}
}
}
}
边栏推荐
猜你喜欢
随机推荐
类和对象(类和类的实例化,this,static关键字,封装)
Service de groupe minecraft
Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
Installing Oracle database 19C RAC on Linux
Call Stack
Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
判断是否是数独
KubeSphere 虚拟化 KSV 安装体验
OpenFeign 簡單使用
Minecraft插件服开服
k8s入门:Helm 构建 MySQL
Routing foundation - dynamic routing
Minecraft module service opening
Application of kotlin - higher order function
Kubesphere virtualization KSV installation experience
寻找链表中值域最小的节点并移到链表的最前面
Minecraft安装资源包
Gateway is easy to use
Qt的connect函数和disconnect函数
What is SQL injection








