Ejemplo n.º 1
0
 private void Resize(string inputFolder, string outputFolder, int fileCount)
 {
     if (!Directory.Exists(outputFolder))
     {
         Directory.CreateDirectory(outputFolder);
     }
     foreach (string subDir in Directory.EnumerateDirectories(inputFolder)
              .Where(f => string.Compare(f, outputFolder, true) != 0))
     {
         Resize(subDir, Path.Combine(outputFolder, Path.GetFileName(subDir)), fileCount);
     }
     CompressionInfo += string.Format("Folder {0}\r\n", outputFolder);
     foreach (string imgFile in Directory.EnumerateFiles(inputFolder).Where(p => ImageCompressor.IsImage(p)))
     {
         if (Notifier != null)
         {
             Notifier((int)(100.0 * fileIndex++ / fileCount), Path.GetFileName(imgFile));
         }
         ImageCompressor ic    = new ImageCompressor(imgFile);
         string          error = ic.SaveAs(Path.Combine(outputFolder,
                                                        Path.GetFileNameWithoutExtension(imgFile) + "." + OutputFileType),
                                           OutputFileType, maxFileSize, maxSize, JpgCompressionLevel);
         CompressionInfo += ic.CompressionInfo + "\r\n";
         if (!string.IsNullOrEmpty(error))
         {
             CompressionInfo += "*** " + error + "\r\n";
             throw new ArgumentException("Error resizing " + imgFile + ", " + error);
         }
     }
 }
Ejemplo n.º 2
0
        private int CountFiles(string inputFolder, string outputFolder)
        {
            int files = 0;

            foreach (string subDir in Directory.EnumerateDirectories(inputFolder)
                     .Where(f => string.Compare(f, outputFolder, true) != 0))
            {
                files += CountFiles(subDir, outputFolder);
            }
            files += Directory.EnumerateFiles(inputFolder).Where(p => ImageCompressor.IsImage(p)).Count();
            return(files);
        }