|
-
Apr 7th, 2009, 01:27 PM
#1
Thread Starter
Fanatic Member
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.
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 7th, 2009, 04:46 PM
#2
Member
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
In case I forget: I'm using Visual Basic 2008 Express Edition...
Should I, in my odd, bumbling way, actually offer some assistance, feel free to show me some RATE love.
Just Another Laptop Hero
-
Apr 7th, 2009, 05:14 PM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|