web Image to Picture Box

  • Thread starter Thread starter Brian P. Hammer
  • Start date Start date
Image img = null;
WebRequest wr = WebRequest.Create(imageUrl);
using(WebResponse response = wr.GetResponse()) {
using(Stream stream = response.GetResponseStream()) {
img = Image.FromStream(stream);
stream.Close();
}
wr.Close();
}

if ( img != null ) { pictureBox.Image = img; }


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
All - How can I get an image from the web into a picturebox on a form?

E.g.
If I have an image at http://www.mywebsite.com/cgi-bin/sty?RANGE=1580@DAL&STYLE=best and want to get it into a picture box on my form.

Thanks,
Brian P. Hammer
 
Thanks Justin. Just what I needed. Here it is in VB for those that need
it.

Dim imageUrl As String = "http://www.caap.com/"
Dim img As Image = Nothing
Dim wr As WebRequest = WebRequest.Create(imageUrl)
Dim response = wr.GetResponse()

Dim stream As System.IO.Stream = response.GetResponseStream()
img = Image.FromStream(stream)
stream.Close()
If Not img Is Nothing Then
pctRangeMap.Image = img
End If

--
Brian P. Hammer


Image img = null;
WebRequest wr = WebRequest.Create(imageUrl);
using(WebResponse response = wr.GetResponse()) {
using(Stream stream = response.GetResponseStream()) {
img = Image.FromStream(stream);
stream.Close();
}
wr.Close();
}

if ( img != null ) { pictureBox.Image = img; }


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
All - How can I get an image from the web into a picturebox on a form?

E.g.
If I have an image at
http://www.mywebsite.com/cgi-bin/sty?RANGE=1580@DAL&STYLE=best and want to
get it into a picture box on my form.

Thanks,
Brian P. Hammer
 
Back
Top