Save webbrowser's images to file
Hello all,
Most programmers hate to read, so first, here is the short version of my question:
Is there a method like WebBrowser1.Document.Image(0).SaveImageToFile("C:\Image.jpg") ?
If you have no direct solution, but are willing to help me (how very kind of you :)), please read on...
I'm trying to make an application that downloads all the images from a photo album on the web. The user will navigate to the first image in the gallery and the program should download all images in full resolution automatically.
I have a working version now, but it is not satisfactory. Here is a simplified version of the code I use now for saving the images:
Code:
Private Sub startDownloading Handles WebBrowser1.DocumentCompleted
My.Computer.Network.DownloadFile(WebBrowser1.Document.Images(0).GetAttribute("src"), "C:\image.jpg")
End Sub
This way, after the page with the image has fully loaded, it downloads the image using the Network.DownloadFile-method. So, it download the same file twice. But these files are big and websites are slow. Which makes the whole operation take about twice as long as it has to.
Is there a way to directly save the image-file that has already loaded in the WebBrowser-control, without having to download the image again?
Thanks for any help,
Alexander.
P.S. The images have semi-random names, so there's no automation possible there.
Re: Save webbrowser's images to file
Is it really necessary to use the WebBrowser Control? Why not just access and save them directly?
Example Here
Re: Save webbrowser's images to file
Maybe this will work? I think it does, but you should be able to tell if it cuts your download times down for saving the images.
Code:
Private Sub startDownloading() Handles WebBrowser1.DocumentCompleted
'USE WEBCLIENT
Dim wc As New Net.WebClient
Try
'SET CACHE POLICY TO LOCAL CACHE ONLY
wc.CachePolicy = New Net.Cache.RequestCachePolicy(Net.Cache.RequestCacheLevel.CacheOnly)
'DOWNLOAD IMAGE, SHOULD BE COMING FROM LOCAL CACHE
wc.DownloadFile(WebBrowser1.Document.Images(0).GetAttribute("src"), "C:\image.jpg")
Catch ex As Net.WebException
'IMAGE IS NOT IN LOCAL CACHE
Catch ex As Exception
'OTHER ERROR
Finally
wc.Dispose()
End Try
End Sub