|
-
Jan 5th, 2000, 08:22 PM
#1
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!)
-
Jan 5th, 2000, 08:50 PM
#2
Frenzied Member
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).]
-
Jan 5th, 2000, 08:59 PM
#3
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!)
-
Jan 31st, 2000, 03:30 PM
#4
Junior Member
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!
-
Feb 1st, 2000, 01:14 AM
#5
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]
-
Feb 8th, 2000, 02:51 AM
#6
Junior Member
Thanks Aaron!
The code help me out a LOT!
-
Feb 8th, 2000, 06:02 AM
#7
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
|