I know that an image can be downloaded from a website opened in web browser control, but that actually works by getting the image URL and download that. There is a website that doesn't allow the direct link, so the image fails to download, so the only method I can think of is copying the images from the cache of the web browser control.
            Asked
            
        
        
            Active
            
        
            Viewed 3,246 times
        
    0
            
            
        - 
                    http://stackoverflow.com/questions/7274329/load-image-from-webbrowser-without-redownloading-or-copying – volody Jun 02 '13 at 00:05
 - 
                    on it seems good but it seems to be in C#, can you help please – Junaid Rehman Jun 02 '13 at 07:04
 
1 Answers
1
            
            
        You can use online c# to vb.net converters like telerik or developerfusion to get code in vb.net in the future.
- Add reference to Microsoft.mshtml to your project
 - Add next code into the webBrowser DocumentCompleted event handler
 
Sample code:
Private Sub webBrowser1_DocumentCompleted(sender As Object, _
   e As WebBrowserDocumentCompletedEventArgs) _
   Handles WebBrowser1.DocumentCompleted
   Dim doc As IHTMLDocument2 = _
      DirectCast(webBrowser1.Document.DomDocument, IHTMLDocument2)
   Dim imgRange As IHTMLControlRange = _
      DirectCast(DirectCast(doc.body, _
      HTMLBody).createControlRange(), IHTMLControlRange)
   For Each img As IHTMLImgElement In doc.images
    imgRange.add(DirectCast(img, IHTMLControlElement))
    imgRange.execCommand("Copy", False, Nothing)
    Using bmp As Bitmap = DirectCast( _
        Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap)
        bmp.Save("C:\" + img.nameProp)
    End Using
   Next
End Sub
        volody
        
- 6,946
 - 3
 - 42
 - 54
 
- 
                    why does it say IHTMLDocument2 not defined? I have added the reference to mshtml already.. and same error for IHTMLControlRange and IHTMLImgElement – Junaid Rehman Jun 03 '13 at 07:16
 - 
                    ok that issue is resolved, but files not not saved and not even on clipboard – Junaid Rehman Jun 03 '13 at 10:12
 - 
                    doc.images collection will enumerate only main document images (top frame), maybe your images are under frames collection – volody Jun 03 '13 at 15:38
 - 
                    @user64: How do I do the same thing but to the pictures inside a particular iFrame? – Osprey Jul 22 '13 at 11:27
 - 
                    use the Frames property, sample code is in http://msdn.microsoft.com/en-us/library/system.windows.forms.htmlwindow.frames.aspx – volody Jul 22 '13 at 15:14