Results 1 to 7 of 7

Thread: Getting images off the web?

  1. #1
    Guest

    Post

    How do you load a picture off the web into a picture box? E.G. how would I display "http://www.vb-world.net/images/vbworld.gif" into a picture box?

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ:31422892
    Web Sites:The Blue Link My Home Page (Not up at the moment!)

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    put a picturebox,internettranfer control and a button on a form and this code:

    Code:
    Private Sub Command1_Click()
    Dim localFile As String
    Dim RemoteFile As String
    Dim fnum As Long
    RemoteFile = "http://www.vb-world.net/images/vbworld.gif"
    localFile = "c:\tmp.pic"
     
        Dim b() As Byte
        Dim strURL As String
    
        ' Retrieve the file as a byte array.
        b() = Inet1.OpenURL(RemoteFile, icByteArray)
        fnum = FreeFile
        Open localFile For Binary Access _
        Write As fnum
        Put fnum, , b()
        Close fnum
        Picture1.Picture = LoadPicture(localFile)
    End Sub
    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company


    [This message has been edited by Mark Sreeves (edited 01-06-2000).]

  3. #3
    Guest

    Post

    thank you! thank you! thank you! thank you!

    thought no one was ever going to reply to that one!

    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ:31422892
    Web Sites:The Blue Link My Home Page (Not up at the moment!)

  4. #4
    Junior Member
    Join Date
    Jan 2000
    Location
    Chicago, IL
    Posts
    26

    Post

    Hi Mark

    Thanks a Ton for that snipplet. Can you suggest a way that i could I could say have my application go to a website and download all the images on the site?

    Thanks!

  5. #5
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's some Example code I just wrote for another question on the same subject, it Downloads the Webpage and all Images along with it into Relevant Directories, giving a True Local Copy of the Website:

    Add a WebBrowser Control, Textbox, Command Button and Inet Control to a Form..
    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        Dim iIndex As Integer
        Dim bitFile() As Byte
        Dim sFile As String
        
        With WebBrowser1.Document
            'Save the HTML Document
            Caption = "Saving: " & .URL & " ..."
            iFile = FreeFile
            Open "C:\Web\Saved.htm" For Output As iFile
                Print #iFile, "<HTML>" & .Body.InnerHTML & "</HTML>";
            Close iFile
            'Loop through the Collection of Images, Downloading Each one
            'And saving it to the appropriate directory
            For iIndex = 0 To .Images.Length - 1
                Caption = "Saving Image: " & iIndex & " - " & .Images(iIndex).NameProp
                bitFile() = Inet1.OpenURL(.Images(iIndex).href, icByteArray)
                sFile = "C:\Web\" & Replace(Mid$(.Images(iIndex).href, Len(.URL) + 1), "/", "\")
                'If the File Exists, Delete it
                If Len(Dir(sFile)) Then Call Kill$(sFile)
                'Make sure the Destination Directory Path Exists
                CreateDir Left$(sFile, InStrRev(sFile, "\"))
                'Save the Image to the Local Disk
                iFile = FreeFile
                Open sFile For Binary Access Write As iFile
                    Put #iFile, , bitFile
                Close iFile
            Next
            Caption = "Done."
        End With
        'All Done.
        MsgBox "Done"
    End Sub
        
    Private Sub Form_Load()
        'Blank the Browser
        WebBrowser1.Navigate ""
    End Sub
    
    Private Sub Form_Resize()
        'Resize Browser Window when Form Resizes
        WebBrowser1.Move 0, 500, ScaleWidth, ScaleHeight - 500
    End Sub
    
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
            'Navigate to the Entered Webpage
            KeyAscii = 0
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1)
            WebBrowser1.Navigate Text1
        End If
    End Sub
    
    Private Sub CreateDir(ByVal sDir As String)
        'Creates a Directory if it doesn't exist
        Dim aDirs As Variant
        Dim iIndex As Integer
        Dim iDir As Integer
        
        'Get Each Component of the Directory
        aDirs = Split(sDir, "\")
        On Error Resume Next
        For iIndex = 0 To UBound(aDirs)
            If InStr(aDirs, ":") = 0 Then
                sDir = ""
                'Progressively build the Path, creating
                'Sub Directories as we go.
                For iDir = 0 To iIndex
                    sDir = sDir & aDirs(iDir) & "\"
                Next
                MkDir sDir
            End If
        Next
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  6. #6
    Junior Member
    Join Date
    Jan 2000
    Location
    Chicago, IL
    Posts
    26

    Post

    Thanks Aaron!

    The code help me out a LOT!


  7. #7
    Guest

    Post

    Hey! My post! My post!



    ------------------
    Matthew Ralston
    E-Mail: [email protected]
    ICQ: 31422892
    Web Site: My Home Page
    AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums)

    Sorry about my English, but my Scouse is dead good!

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