?
Solved

Load a web image in VB.net

Posted on 2005-04-13
13
Medium Priority
?
435 Views
Last Modified: 2008-02-01
Dear Sirs,

Is there anyway of retrieving an image from a URL and displaying it in a picturebox?
0
Comment
Question by:watersidedesigns
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 1

Expert Comment

by:karlossos
ID: 13772139
I would probably use a socket to connect to the web page.
Then pull the image from the web site to a temporary location.
then direct the picture box there.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetsocketssocketclasstopic.asp

Here is some info on using sockets.

You will want to use the connect method to get the web site.

cheers.
0
 
LVL 18

Expert Comment

by:armoghan
ID: 13772543
Three methods to do it apart from the above mentioned

1. http://weblogs.asp.net/psteele/articles/7533.aspx
2. http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=32290 . File stream can be URL as well
3. Use IE control instead of PictureBox. Though it would be heavy but it can easily have an Image from a URL
0
 
LVL 12

Accepted Solution

by:
S-Twilley earned 2000 total points
ID: 13772548
You have a few different options really...

Either use a WebBrowser control as a replacement picturebox, and use the Navigate2 Method to point it to the URL of the picture...

or as karlossos was directing at, downloading the image and displaying it... there's probably a proper way of doing it but you can use the WebClient class to download a file, and you could open that file into the picturebox, or download the data into an array of bytes and somehow transfer that into the picturebox (not at a machine with vb.net to try this out)... if i remember...

Imports System.Net

==========

Sub X()
    Dim wc as New WebClient
    Dim arrData() as Byte = wc.DownloadData("http://blah.com/ex.gif")  'something like this

    ' as for getting the bytes into the picturebox im not sure, i'll get back to you on that if no one else does
End Sub

the other method

Sub Y()
    Dim wc as New WebClient
    wc.DownloadFile("http://blah.com/ex.gif","c:\test.gif")
    Picturebox1.Image = New Bitmap("C:\test.gif")
End Sub

============

A word of warning, the webclient class, and the downloadXXXX methods will cause the current  thread to lock until the download is complete, so either do it on a seperate thread or use the WebRequest/WebResponse classes which take a bit more programming
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:S-Twilley
ID: 13772556
Ahh sorry armoghan... was a bit slow on the typing there... sorry to step on your toes
0
 
LVL 18

Expert Comment

by:armoghan
ID: 13773031
NP
It happens all the time :)

For that I used to wish that EE shoudl work like IM :)
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13773110
I usually type out my response, copy it to the clipboard, refresh the page to check no one has posted, then paste it back in and submit... but Im just getting lazy nowadays
0
 

Author Comment

by:watersidedesigns
ID: 13773424
Hi Guys,

Thanks for all the responses.  As it happen I need to wait for the download to complete before I can continue so I have tried the webclient download mentioned by S-Twilley.  However, whilst there is a pause as if something is happening, no image is downloaded.

Any Ideas?
0
 

Author Comment

by:watersidedesigns
ID: 13773448
Ignore my last comment, my fault :)

Thanks for all your help
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13773457
well there's always going to be some sort of delay while the image is downloading... but maybe before you start the download, you load a local image into the picture box... maybe a "waiting for download" image... and once the download is complete, override the waiting image with the downloaded one
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13773513
       Dim wc As New Net.WebClient

        Dim x As New Bitmap(wc.OpenRead("http://www.experts-exchange.com/images/expertAwards2004Button.gif"))
        PictureBox1.Image = x

=========

goto vb.net... here's what I was getting at about loading the data straight into a bitmap.
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13773545
You really should have split the points... or even awarded  them all to the other two people... although I did put some sort of code in my comment, the others did post up valid links to solutions... I'm sure they're not going to come around and bust your front door down... but least remember it for next time :P
0
 
LVL 18

Expert Comment

by:armoghan
ID: 13778768
:)
0
 

Author Comment

by:watersidedesigns
ID: 13778988
Sorry guys,  will remember next time :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question