Click to See Complete Forum and Search --> : Getting images off the web?
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: m.ralston@mediavault.co.uk
ICQ:31422892 (http://www.thebluelink.cjb.net/icq.html)
Web Sites:The Blue Link (http://www.thebluelink.cjb.net) My Home Page (http://mralston.cjb.net) (Not up at the moment!)
Mark Sreeves
Jan 5th, 2000, 07:50 PM
put a picturebox,internettranfer control and a button on a form and this 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
Mark.Sreeves@Softlab.co.uk
A BMW Group Company
[This message has been edited by Mark Sreeves (edited 01-06-2000).]
thank you! thank you! thank you! thank you!
thought no one was ever going to reply to that one!
------------------
Matthew Ralston
E-Mail: m.ralston@mediavault.co.uk
ICQ:31422892 (http://www.thebluelink.cjb.net/icq.html)
Web Sites:The Blue Link (http://www.thebluelink.cjb.net) My Home Page (http://mralston.cjb.net) (Not up at the moment!)
Azh
Jan 31st, 2000, 02:30 PM
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!
Aaron Young
Feb 1st, 2000, 12:14 AM
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..
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
aarony@redwingsoftware.com
ajyoung@pressenter.com
Azh
Feb 8th, 2000, 01:51 AM
Thanks Aaron!
The code help me out a LOT!
:( Hey! My post! My post! :(
:)
------------------
Matthew Ralston
E-Mail: matthew@ralston.net
ICQ: 31422892
Web Site: My Home Page (http://www.matthew.ralston.net)
AKA: ...::: The Fragmeinster :::... (On Quake 3 World Forums (http://www.quake3world.com/forums/))
Sorry about my English, but my Scouse is dead good!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.