public static Image GetImageFromUrl(string imageUrl)
{
if (imageUrl == null)
throw new ArgumentNullException("imageUrl");
try
{
var stopWatch = new Stopwatch();
stopWatch.Start();
var request = HttpWebRequest.Create(imageUrl);
using (var response = request.GetResponse())
using (var stream = response.GetResponseStream())
{
MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
stopWatch.Stop();
_log.DebugFormat("Download of image from URL '{0}' took '{1}'", imageUrl, stopWatch.Elapsed);
return new Bitmap(memoryStream);
}
}
catch (Exception ex)
{
throw new HttpException("Could not load remote website.", ex);
}
}