Imagens From WebBrowser

  • 14 years ago


    I´m trying to make an app like a "SiteDownloader". What I realy need is ... navegate to a URL using WebBrowser, detect all images that match some criteria (like extension *.gif, *.jpg) and save this images to HD.

    I´m trying to do something with:

    For k = 0 To WebBrowser1.Document.Images.Count - 1
        Source = WebBrowser1.Document.Images(k).OuterHtml

    But I cant get the entire URL of images to use URLDonwload ...

    Anyone have some idea? Or can show me another way to try a solution?

    (I´m using VB.Net 2005)


  • 14 years ago

    Here is an example that downloads an image from a website then displays it on the form.  You should be able to convert it to save all images to HD.

    Form code:

    Public Class Form1
        Inherits System.Windows.Forms.Form

        Private Sub btnLoadWebImageClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadWebImage.Click
            'Loads a picture box with an image from a website

            Dim PATH
    TOIMAGE As String = ""

            Dim xImage As ImageStream.ImageToDownload = New ImageStream.ImageToDownload(PATH
            Dim xStream As MemoryStream = xImage.BeginDownload()
            picFromWeb.Image = Image.FromStream(xStream)
        End Sub
    End Class

    And for Module1:

    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Text

    Namespace ImageStream

        Public Class ImageToDownload
            Dim sI2D
    URL2Download As String
            Dim PREFIX As String = "http://"

            Public Sub New(ByVal sURL As String)
                Me.sI2DURL2Download = sURL
            End Sub

            Public Function BeginDownload() As MemoryStream
                Dim msImage As MemoryStream
                Dim wcClient As WebClient = New WebClient()

                If Not sI2D
    URL2Download.ToLower().StartsWith("http://") Then sI2DURL2Download = PREFIX + sI2DURL2Download
                msImage = New MemoryStream(wcClient.DownloadData(sI2D_URL2Download))

                Return msImage
            End Function
        End Class

    End Namespace

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Walking on water and developing software from a specification are easy if both are frozen.” - Edward V Berard