Load image from WebBrowser without redownloading o

2019-06-03 05:41发布

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

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?

1条回答
走好不送
2楼-- · 2019-06-03 06:06

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.

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.

查看更多
登录 后发表回答