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


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01