Nicko think on software, web, ideas

July 24, 2007

Loading Image from website

Filed under: Code and Code, think&think — Nicko Satria Utama @ 12:01 pm

 In the System.Drawing, Image can only get from the file and don’t have methods to download the images from the internet. The code below is getting from the url. First define the url. and download the data using stream.

private Image LoadFromURL(string url)
{
Image image = null;
MemoryStream ms = null;
byte[] data = null;
Uri uri = new Uri(url,UriKind.RelativeOrAbsolute);
WebClient webClient = new WebClient();
data = webClient.DownloadData(uri);
ms = new MemoryStream(data);
if (ms != null)
{
image = Image.FromStream(ms);
}
return image;
}

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.