Exemplo n.º 1
0
        public static bool processDirectory(String directory, PhotoConverterOptions ops)
        {
            bool fail = false;
            if (ops.IncludeSubfolders == true)
            {
                //Process all sub folders
                try
                {
                    String[] folderEntries = Directory.GetDirectories(directory);
                    foreach (String folderName in folderEntries)
                    {
                        fail = processDirectory(folderName, ops);
                    }
                }
                catch (Exception)
                {
                    fail = true;
                }
            }
            String outputFolder = ops.OutputPath + directory.Replace(ops.OriginPath, "");
            //Check if output folder exists, if not then create it
            if (Directory.Exists(outputFolder) == false)
            {
                try
                {
                    Directory.CreateDirectory(outputFolder);
                }
                catch (Exception)
                {
                    fail = true;
                }
            }

            //Process all files in current folder
            fail = processFiles(directory, outputFolder, ops);
            return fail;
        }
Exemplo n.º 2
0
        private void btProccess_Click(object sender, EventArgs e)
        {
            bool errors = false;
            //Check values have been set
            if (errors == false && tbSourceFolder.Text == "")
                errors = setError("Select A Source Directory");
            if (errors == false && txtSaveFolder.Text == "")
                errors = setError("Select A Save To Directory");

            if (errors == false)
            {
                lblStatus.Text = "Starting Process...";
                PhotoConverterOptions ops = new PhotoConverterOptions();
                ops.IncludeSubfolders = this.chBRecursion.Checked;
                ops.MaxHeight = Double.Parse(this.tbOutputHeight.Text);
                ops.MaxWidth = Double.Parse(this.tbOutputWidth.Text);
                ops.OriginPath = this.tbSourceFolder.Text;
                ops.OutputPath = this.txtSaveFolder.Text;
                ops.pbTemp = this.pbStatus;

                bool results = PhotoConverter.processDirectory(tbSourceFolder.Text, ops);
                lblStatus.Text = "Done";
            }
        }
Exemplo n.º 3
0
 private static bool processFiles(String inputDir, String outputDir, PhotoConverterOptions ops )
 {
     //For each selected file type in the source directory, do
     String[] fileEntries = Directory.GetFiles(inputDir, "*.*");
     ops.pbTemp.Minimum = 0;
     ops.pbTemp.Maximum = fileEntries.Length;
     ops.pbTemp.Step = 1;
     int fileCount = 0;
     bool fail = false;
     foreach (String fileName in fileEntries)
     {
         if (fail == true)
             break;
         String actualName = fileName.Replace(inputDir + "\\", "");
         Image resizedImage;
         fileCount += 1;
         ops.pbTemp.Value = fileCount;
         try
         {
             resizedImage = resizeImage(ops.MaxWidth, ops.MaxHeight, inputDir + "\\" + actualName);
             resizedImage.Save(outputDir + "\\" + actualName);
         }
         catch (OutOfMemoryException ex)
         {
             setError(actualName + ": El archivo no tiene un formato de imagen válido. GDI+ no admite el formato de píxel del archivo. ");
         }
     }
     ops.pbTemp.Value = 0;
     return fail;
 }