开发者

Load image from WebBrowser without redownloading or copying

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

IHTMLDocument2 doc = (IHTMLDocument2) webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange) ((HTMLBody) doc.body).createControlR开发者_如何学运维ange();

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜