What control is best to use when displaying a url to a jpg file

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hi

I have a string that is representing a url to a jpg file and the image to
this file should be displayed in a suitable control.
What control do you recomment to use ?

//Tony
 
Hi

I have a string that is representing a url to a jpg file and the image to
this file should be displayed in a suitable control.
What control do you recomment to use ?

//Tony

It would seem if it is an image to be displayed, then put it into a
PictureBox control. The fact the source is a url should be irrelevant.
 
Family Tree Mike said:
It would seem if it is an image to be displayed, then put it into a
PictureBox control. The fact the source is a url should be irrelevant.

I use the following code. It works good but you might have a better
suggestion ?
WebRequest req = WebRequest.Create(movie.Url);
WebResponse response = req.GetResponse();
Stream stream = response.GetResponseStream();

//Tony
pictureBox.Image = Image.FromStream(stream);
 
I use the following code. It works good but you might have a better
suggestion ?
WebRequest req = WebRequest.Create(movie.Url);
WebResponse response = req.GetResponse();
Stream stream = response.GetResponseStream();

//Tony
pictureBox.Image = Image.FromStream(stream);

That looks fine, though for no specific reason I tend to prefer:

WebClient client = new WebClient();
Stream stream = client.OpenRead(movie.Url);
pictureBox.Image = Image.FromStream(stream);
 
Family Tree Mike said:
That looks fine, though for no specific reason I tend to prefer:

WebClient client = new WebClient();
Stream stream = client.OpenRead(movie.Url);
pictureBox.Image = Image.FromStream(stream);


Hi!

This is also an alternative where the code is only a single row.
Here I use a webBrowser control
webBrowser.Url = new Uri(movie.Url);
This code is slightly slower then the other two alternatives.

//Tony
 
Back
Top