Esempio n. 1
0
 /// <summary>
 /// Converts a url (filesystem or web) into an <see cref="System.Drawing.Image"/>
 /// </summary>
 /// <param name="url">The url path to the image</param>
 /// <returns>The resulting <see cref="System.Drawing.Image"/></returns>
 public static System.Drawing.Image ImageFromUrl(string url)
 {
     System.Drawing.Image image = null;
     try
     {
         if (!String.IsNullOrEmpty(url))
         {
             Uri uri = new Uri(url);
             if (uri.IsFile)
             {
                 System.IO.FileStream fs = new System.IO.FileStream(uri.LocalPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                 using (fs)
                 {
                     image = ImageFromStream(fs);
                 }
             }
             else
             {
                 WebClientEx wc = new WebClientEx();
                 using (wc)
                 {
                     byte[] bytes = wc.DownloadData(uri);
                     System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes, false);
                     using (ms)
                     {
                         image = ImageFromStream(ms);
                     }
                 }
             }
         }
     }
     catch
     {
     }
     return image;
 }
 /// <summary>
 /// Converts a url (filesystem or web) into an <see cref="System.Drawing.Image"/>
 /// </summary>
 /// <param name="url">The url path to the image</param>
 /// <returns>The resulting <see cref="System.Drawing.Image"/></returns>
 public static System.Drawing.Image ImageFromUrl(string url)
 {
     System.Drawing.Image image = null;
     try
     {
         if (!String.IsNullOrEmpty(url))
         {
             Uri uri = new Uri(url);
             if (uri.IsFile)
             {
                 System.IO.FileStream fs = new System.IO.FileStream(uri.LocalPath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
                 using (fs)
                 {
                     image = ImageFromStream(fs);
                 }
             }
             else
             {
                 WebClientEx wc = new WebClientEx();
                 using (wc)
                 {
                     byte[] bytes = wc.DownloadData(uri);
                     System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes, false);
                     using (ms)
                     {
                         image = ImageFromStream(ms);
                     }
                 }
             }
         }
     }
     catch
     {
     }
     return(image);
 }