Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Webimage in a picturebox 1

Status
Not open for further replies.

GertJannie

Programmer
Nov 24, 2005
13
BE
Hi, is it possible to show a webimage in a picturebox?
Thx in advance.
 
like an image from a website like the google logo ?

if so then heres an example, this requires:
using System.Net;
using System.IO;

set you picturBox image to GetImage("someurltoimage")
e.g picturBox1.Image=GetImage("


Code:
private Image GetImage(string sURL)
{
	Stream str = null; 		
			
	try
	{
	//Create a web request to the url containing the image
		HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(sURL);
	
	//optional: use only if you're using a proxy to connect to the internet			
		//wReq.Proxy = SetWebProxy();
				
	//gets the response from the web request 
		HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
					
	//return the image stream from the URL specified earlier
		str = wRes.GetResponseStream();
	}
	catch (Exception Ex)
	{
		MessageBox.Show(Ex.Message);
	}

	if (str != null)
		return Image.FromStream(str);
	else 
		return null;
}

the above works nicely, but bear in mind I'm a relative n00b so theres probably an easier/better way.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top