save images in webbrowser control without redownloading them from the internet(将图像保存在 webbrowser 控件中,而无需从 Internet 重新下载它们)
问题描述
是否可以将网络浏览器控件中的图像直接保存到硬盘,而无需再次从 Internet 下载?
Is it possible to save images in a webbroswer control directly to hard disk, without needing to download them again from the internet?
假设我导航到一个有 15 张图片的网站.它们都在我的网络浏览器中查看,但我现在如何保存它们而不需要下载它们?
Let's say I navigate to a website that has 15 images. They are all viewed in my webbrowser, but how can I save them now without the need to download them?
推荐答案
这是我能找到的唯一方法.想知道其他人是否有更好的方法.
This is the only way I could find. Curious if anyone else has a better way.
复制自 CodeProject
您必须添加对 Microsoft.mshtml 的引用,当然还要等待文档完成加载.这将保存在 System.Windows.Forms.WebBrowser webBrowser1 组件中加载的图像 - 甚至是您不想要的图像.
You have to add a reference to Microsoft.mshtml and of course wait for the document to finish loading. This will save the images loaded in a System.Windows.Forms.WebBrowser webBrowser1 component - even the ones you don't want.
IHTMLDocument2 doc = (IHTMLDocument2) webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange) ((HTMLBody) doc.body).createControlRange();
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement) img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap) Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(@"C:"+img.nameProp);
}
}
这篇关于将图像保存在 webbrowser 控件中,而无需从 Internet 重新下载它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将图像保存在 webbrowser 控件中,而无需从 Internet 重新下载它们
基础教程推荐
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- WPF 模态进度窗口 2022-01-01
