I\'m using VB.Net I have an url of an image, let\'s say http://localhost/image.gif
I need to create a System.Drawing.Image object from that
The other answers are also correct, but it hurts to see the Webclient and MemoryStream not getting disposed, I recommend putting your code in a using.
Example code:
using (var wc = new WebClient())
{
using (var imgStream = new MemoryStream(wc.DownloadData(imgUrl)))
{
using (var objImage = Image.FromStream(imgStream))
{
//do stuff with the image
}
}
}
The required imports at top of your file are System.IO, System.Net & System.Drawing
In VB.net the syntax was using wc as WebClient = new WebClient() { etc