Esempio n. 1
0
        ///<summary>
        /// Get an image from a path, be it file, ftp, http, zip, res, etc.
        ///</summary>
        ///<param name="path"></param>
        ///<returns></returns>
        public static Image FromFile(string path)
        {
            Image image;

            using (Stream stream = PathHelper.GetReadStream(path))
            {
                // fixing the strange Out of memory exception from System.Drawing
                using (Image image2 = Image.FromStream(stream))
                {
                    image = image2.GetThumbnailImage(image2.Width, image2.Height, null, IntPtr.Zero);
                }
            }
            return(image);
        }
Esempio n. 2
0
 /// <summary>
 /// When overridden in a descendant class, returns the data stream from the Internet resource.
 /// </summary>
 /// <returns>
 /// An instance of the <see cref="T:System.IO.Stream"/> class for reading data from the Internet resource.
 /// </returns>
 /// <exception cref="T:System.NotSupportedException">Any attempt is made to access the method, when the method is not overridden in a descendant class. </exception><PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence"/></PermissionSet>
 /// <exception cref="FileNotFoundException"><c>FileNotFoundException</c>.</exception>
 public override Stream GetResponseStream()
 {
   Stream resultStream;
   using (Stream stream = PathHelper.GetReadStream(_archive))
   {
     using (ZipFile zipFile = new ZipFile(stream))
     {
       ZipEntry zipEntry = zipFile.GetEntry(_file);
       if (zipEntry == null)
       {
         throw new FileNotFoundException(string.Format("file {0} not found in archive {1}", _file, _archive));
       }
       using (Stream zipStream = zipFile.GetInputStream(zipEntry))
       {
         resultStream = PathHelper.GetSafeReadStream(zipStream);
       }
     }
   }
   return resultStream;
 }