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 重新下载它们


- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01