By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,144 Members | 1,250 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,144 IT Pros & Developers. It's quick & easy.

Displaying an image url in c#

P: n/a
Hi,

I have an image url (eg:http://myimages.com/pic1.jpg)
Now i want to display the above image in a C# windows form.
Which control should i use?
i am using VS .NET 2003.

Pls provide some example code.

Regards,
Kiran
Mar 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You can use PictureBox to show the images in Windows Forms. You can't
directly load images from URI location. You will have to download them first
using System.Net.WebRequest and System.Net.WebResponse classes, and then load
the image from the saved location and show it in PictureBox.

Following article shows some sample code on how to dowload images from URI
location:
http://www.gotdotnet.com/Community/M...=164268&Page=1

Once downloaded you can use following code to load the file into PictureBox:

pictureBox1.Image = System.Drawing.Image.FromFile(@"Path\YourFile.jpg" );
Mar 22 '06 #2

P: n/a
Try this:

private Bitmap LoadPicture(string url)
{
HttpWebRequest wreq;
HttpWebResponse wresp;
Stream mystream;
Bitmap bmp;

bmp = null;
mystream = null;
wresp = null;
try
{
wreq = (HttpWebRequest)WebRequest.Create(url);
wreq.AllowWriteStreamBuffering = true;

wresp = (HttpWebResponse)wreq.GetResponse();

if ((mystream = wresp.GetResponseStream()) != null)
bmp = new Bitmap(mystream);
}
finally
{
if (mystream != null)
mystream.Close();

if (wresp != null)
wresp.Close();
}

return (bmp);
}

an then...
pictureDetail.Image = LoadPicture(strURL);
where pictureDetail is image control.

Mar 22 '06 #3

P: n/a
The PictureBox in 2.0 supports loading from a URL.

"yogeshprabhu" <yo**********@discussions.microsoft.com> wrote in message
news:69**********************************@microsof t.com...
You can use PictureBox to show the images in Windows Forms. You can't
directly load images from URI location. You will have to download them
first
using System.Net.WebRequest and System.Net.WebResponse classes, and then
load
the image from the saved location and show it in PictureBox.

Following article shows some sample code on how to dowload images from URI
location:
http://www.gotdotnet.com/Community/M...=164268&Page=1

Once downloaded you can use following code to load the file into
PictureBox:

pictureBox1.Image = System.Drawing.Image.FromFile(@"Path\YourFile.jpg" );

Mar 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.