从WebBrowser加载图像,而无需重新下载或复制 [英] Load image from WebBrowser without redownloading or copying

查看:55
本文介绍了从WebBrowser加载图像,而无需重新下载或复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在从剪贴板复制以从浏览器加载图像

I am currently copying from clip board to load image from browser

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);
  }
}

但是使用剪贴板有一些问题。还有其他方法可以做到这一点。在Internet Explorer中,所有图像都进入temp目录,如果发生相同的情况,是否有任何方法可以获取该保存图像的路径?

But it has some problems using clipboard. Is there any other way to do that. In internet explorer all images go to temp directory, if same happens here is there any way to get path of that saved image?

推荐答案

对于页面上的每个图像,您可以收集其URL,然后调用WinINET缓存枚举功能(例如FindFirstURLCacheEntry)以在Internet临时文件文件夹中找到后备缓存文件。但是,不能保证文件会在高速缓存中,因为它可能已经带有禁止缓存的头文件了,等等。

For each image on the page, you can collect its URL then call the WinINET cache enumeration functions (e.g. FindFirstURLCacheEntry) to locate the backing cache file in the Temporary Internet Files folder. However, there's no guarantee that the file will be in the cache because it may have been delivered with headers that forbid caching, etc.

您可以考虑使用的一种方法是使用FiddlerCore (www.fiddler2.com/core)在您的应用程序中;然后,您可以离线抓取所有已传输的图像,然后对它们进行任何操作。

One approach you could consider is using FiddlerCore (www.fiddler2.com/core) in your application; you could then snag all transferred images "off the wire" and do whatever you want with them.

这篇关于从WebBrowser加载图像,而无需重新下载或复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆