Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Placing a image from a web site on a form 6

Status
Not open for further replies.

progolf069

Programmer
Jun 13, 2001
37
US
Here is my situation: I am trying to develop an application that will go out to a web site, and download a picture and display it on a form (in either a picture box or an image box) Here is some more detail: I am living in Decatur, Illinois, and we have a local television station that has a live doppler radar. Well, this live doppler radar, for internet purposes, takes pictures every two minutes and upload that image to the web site. The image can be viewed at this URL: I would like to be able to take this URL, and have it display in a picture box or image box on my Visual Basic form. Can anybody send over some code that might help me, or give me a suggestion that they have previously used on their application(s)? Thanks for your help everybody!
 
Here's one way. You need to put an Internet Transfer control and a picture box onto a form along with a command button. Then just drop this code in.

Note, no error handling or image resizing code is included.


Option Explicit

Private Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long


Private Sub Command1_Click()

Picture1.Picture = GetPicFromHTTP("
End Sub


Private Function GetPicFromHTTP(strURL As String) As Variant
Dim strTempPath As String * 512
Dim strTempFileBuff As String * 576
Dim strTempFile As String

Dim hFile As Long

Dim result As Long

Dim bytearray() As Byte
Dim strData As String

' Generate unique temporary filename
result = GetTempPath(512, strTempPath)
GetTempFileName strTempPath, "VBT", 0, strTempFileBuff
strTempFile = Left$(strTempFileBuff, InStr(strTempFileBuff, vbNullChar) - 1) + ".jpg"

bytearray() = Inet1.OpenURL(strURL, icByteArray)
'strData = Inet1.OpenURL(" icString)
hFile = FreeFile

Open strTempFile For Binary As hFile
Put hFile, , bytearray
Close hFile

Set GetPicFromHTTP = LoadPicture(strTempFile)
Kill strTempFile
End Function
 
Thanks for the help, I have spent many hours looking for this feature, and it now works! Excellent job presenting the code, keep up the good work! Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top