将图像保存在 webbrowser 控件中,而无需从 Internet 重新下载它们

save images in webbrowser control without redownloading them from the internet(将图像保存在 webbrowser 控件中,而无需从 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 重新下载它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)