|
-
Dec 6th, 2002, 06:50 AM
#1
Thread Starter
Addicted Member
Load image from URL into Picturebox at runtime
I want to load an image into a PictureBox from a URL at runtime. Any ideas how?
I was attempting to do it like this
Code:
' Get image
Dim oXMLHTTP As New MSXML2.XMLHTTP()
oXMLHTTP.open("GET", "http://www.site.com/image.jpg")
oXMLHTTP.send()
Dim strImage As System.IO.Stream = oXMLHTTP.responseStream
oXMLHTTP = Nothing
' Load image into Picture Box
picProductImage.Image = Image.FromStream(strImage)
but it told me that the cast (data type?) of the responsestream and image objects didn't match. I also tried using
Code:
picProductImage.Image = Image.FromFile("http://www.site.com/image.jpg")
Only to be told that the FromFile method didn't support URLs.
So I'm stuck.
-
Dec 6th, 2002, 07:53 AM
#2
Member
Did you try using Ctype() function?
U S A
Visual Studio .NET
Windows XP
-
Dec 6th, 2002, 08:08 AM
#3
Thread Starter
Addicted Member
Well I changed line 6 of the code I posted to
Code:
Dim strImage As System.IO.Stream = CType(oXMLHTTP.responseStream, System.IO.Stream)
but the message is still the same
An unhandled exception of type 'System.InvalidCastException' occurred in macXchange Admin.exe
Additional information: Specified cast is not valid.
-
Dec 6th, 2002, 08:12 AM
#4
yay gay
use webclient instead or httpclient
dim wc as new WebClient()
wc.downloaddata()
\m/  \m/
-
Dec 6th, 2002, 09:00 AM
#5
Registered User
Code:
Dim url As String = "http://www.site.com/image.jpg"
Dim wreq As System.Net.HttpWebRequest = System.Net.WebRequest.Create(url)
Dim wres As System.Net.HttpWebResponse = wreq.GetResponse
PictureBox1.Image = System.Drawing.Image.FromStream(wres.GetResponseStream)
-
Dec 6th, 2002, 06:19 PM
#6
Thread Starter
Addicted Member
System.Net Thank you! I was sure there must be some namespace with stuff to do what I wanted, but I couldn't find it. I was looking through System.Web but couldn't find much useful. Using the XML object was a last ditch effort anyway. 
I feel rather silly now for not spotting that namespace!
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
|