Results 1 to 3 of 3

Thread: Save webbrowser's images to file

  1. #1

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    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!

  2. #2
    Member GeekInOhio's Avatar
    Join Date
    Jun 2008
    Location
    You'll never guess...
    Posts
    56

    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

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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
  •  



Click Here to Expand Forum to Full Width