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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loadpicture from a URL

Status
Not open for further replies.

capone67

Programmer
Nov 6, 2000
115
0
0
CA
Hi gang

I am looking for a way to use the loadpicture command with a picture that is online. Any ideas as to how I can do this?

Ken
 
I would use the Microsoft internet control instead of a picture box or image control.
Todd Norris
Hope this helps !
 
Create a form with a picturebox and command button, then try the following code:

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(&quot;<picture URL that you are interested in>&quot;)

End Sub


Private Function GetPicFromHTTP(strURL As String) As StdPicture
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, &quot;VBT&quot;, 0, strTempFileBuff
strTempFile = Left$(strTempFileBuff, InStr(strTempFileBuff, vbNullChar) - 1) + &quot;.jpg&quot;

bytearray() = Inet1.OpenURL(strURL, icByteArray)
hFile = FreeFile

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

Set GetPicFromHTTP = LoadPicture(strTempFile)
Kill strTempFile
End Function
 
Oh, I should point out that the example given assumes that you are dealing with a JPEG image, but is easily adaptable to other formats merely by changing the extension added in the stTemp assigment line.
 
I caught the jpg gif thing when I was looking at the code. I'll ave to make a slight modification to the code to del with that. I have Added the reffernce to the Miscrosoft Internet Controls to my project but I don't see anything in my tool box for it.

How do I add the control to my project? This looks like it will meet my needs easily.

TIA

Ken
 
Thanks for your help. My system has issues so I re-installed VB under a differnt administrators login and everything works beautifully now. Any idea why software installs tell me that I need administrative permissions even though when I look in the user manager I am an Administrator?

Ken
 
>I caught the jpg gif thing

Sorry if I was doing a 'teaching grandmother to suck eggs' thing. It's sometimes difficult to tell here the level of knowledge that people come in with.

Frankly, if I was doing this sort of properly I guess I'd parse the extension of the requested file, and therefore make my temporary file follow that. There are still some limitations, as I suspect you know, in what a Picture Box will handle (or, more accurately, what LoadPicture will handle).

Glad the reinstall helped out - but I'm not going to pretend I understand why you currently have an Admin problem...

Have fun.

Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top