Loading an image residing on a remote web server to a image control.

This has been a question posted to me on an internet site. Initially i thought this had to be simple. But then I realized, in order to do this you need to do a few lines of coding. This was for a Pocket PC application. But anyways coding would not change much for any other platform.

Here it is:

‘Give the url as a string
private void LoadImage1(string url, PictureBox pb){
HttpWebRequest wReq = null;
HttpWebResponse wRes = null;

try{
wReq = (HttpWebRequest)WebRequest.Create(url);
wRes = (HttpWebResponse)wReq.GetResponse();
pb.Image = new System.Drawing.Bitmap(wRes.GetResponseStream());
}
catch(Exception ex){
string s = ex.Message;
}
finally {
wRes.Close();
}
}




    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s



%d bloggers like this: