Example #1
0
        // Here lies applications of image effects and file handling
        private void menuBatch_Click(object sender, EventArgs e)
        {
            using (BatchSettings bs = new BatchSettings(this))
            {
                if (bs.ShowDialog() == DialogResult.OK)
                {
                    // Distinguish new collection, which images to apply Batching to?
                    List<LoadedImage> listBatch = new List<LoadedImage>();

                    for (int i = 0; i < listLoadedImg.Count; i++)
                    {
                        // Add each item that is marked for processing to the new batch list, arrIsProcessed is populated in bs.GrabInputValues()
                        if (bs.arrIsProcessed[i] == true)
                        {
                            listBatch.Add(listLoadedImg[i]);
                        }
                    }

                    // Used for iterating filenames
                    int suffix = 0;

                    // Loop through each image
                    foreach (LoadedImage batchImg in listBatch)
                    {
                        suffix++; // Only iterate when moving to the next image
                        ApplyBatchSettingsEffects(bs, batchImg); // Apply all effects before file processing
                        batchImg.ApplyPreview();

                        // If Exporting to file & Channels are not being exported
                        if (bs.arrChkOptions[0][0].Checked && !bs.arrChkOptions[4][0].Checked)
                        {
                            // Grab the curent ImageFormat from the bs form
                            ImageFormat expFormat = bs.GetImageFormat();
                            string filename, fileDir, filePath;

                            if (bs.provideDir)
                            {
                                fileDir = bs.GetValue("newFileDir");
                            }
                            else
                            {
                                fileDir = batchImg.defaultDir;
                            }

                            // if providing new file deaultName, and there's more than one image being exported
                            if (bs.provideName && listBatch.Count > 1)
                            {
                                filename = bs.GetValue("newFileName") + "_" + suffix.ToString();
                            }
                            // If (for some reason) there is only one image in the batch
                            else if (bs.provideName && listBatch.Count == 1)
                            {
                                filename = bs.GetValue("newFileName");
                            }
                            else
                            {
                                filename = batchImg.deaultName;
                            }

                            // Generate a full path based on name + directory
                            filePath = fileDir + "\\" + filename + "." + expFormat.ToString();
                            // batchImg.GetBitmap("c").Save(filePath, expFormat);
                            SaveImage(filePath, batchImg.GetBitmap("c"), expFormat);
                        }
                        // Exporting to file & exporting channels
                        else if (bs.arrChkOptions[0][0].Checked && bs.arrChkOptions[4][0].Checked)
                        {
                            // 4 channels, R, G, B, A
                            // Create a new array of Bitmaps, length based on maximum number to be exported
                            Bitmap[] imgExportChannels = new Bitmap[4];

                            // Loop through each channel position
                            for (int i = 0; i < 4; i++)
                            {
                                // if the checkbox is checked (e.g. "R") on the Batch dialog
                                if (bs.arrChannelOptions[i].Checked)
                                {
                                    string channelName = "";
                                    // Based on the channel position, Get a channel from the previewVer of this image.
                                    // Put that result into this new array of channel images
                                    switch (i)
                                    {
                                        case 0: // R
                                            {
                                                imgExportChannels[i] = adjustImg.GetChannel("r", batchImg.GetBitmap("c"));
                                                channelName = "R";
                                            } break;
                                        case 1: // G
                                            {
                                                imgExportChannels[i] = adjustImg.GetChannel("g", batchImg.GetBitmap("c"));
                                                channelName = "G";
                                            } break;
                                        case 2: // B
                                            {
                                                imgExportChannels[i] = adjustImg.GetChannel("b", batchImg.GetBitmap("c"));
                                                channelName = "B";
                                            } break;
                                        case 3: // Alpha
                                            {
                                                if (bs.exportAlphaBW)
                                                {
                                                    imgExportChannels[i] = adjustImg.GetChannel("abw", batchImg.GetBitmap("c"));
                                                    channelName = "A"; // use the same suffix for both the alpha export options
                                                }
                                                else if (bs.exportAlphaTransp)
                                                {
                                                    imgExportChannels[i] = adjustImg.GetChannel("a", batchImg.GetBitmap("c"));
                                                    channelName = "A"; // use the same suffix for both the alpha export options
                                                }
                                            } break;
                                        default:
                                            {
                                                Environment.Exit(26);
                                            } break;

                                    }
                                    // Consider that there is some repeated code from the above save functionailty

                                    // Grab the curent ImageFormat from the bs form
                                    ImageFormat expFormat = bs.GetImageFormat();
                                    string filename, fileDir, filePath;

                                    if (bs.provideDir)
                                    {
                                        fileDir = bs.GetValue("newFileDir");
                                    }
                                    else
                                    {
                                        fileDir = batchImg.defaultDir;
                                    }

                                    // if providing new file deaultName, and there's more than one image being exported
                                    if (bs.provideName && listBatch.Count > 1)
                                    {
                                        filename = bs.GetValue("newFileName") + "_" + suffix.ToString() + "_" + channelName;
                                    }
                                    // If (for some reason) there is only one image in the batch
                                    else if (bs.provideName && listBatch.Count == 1)
                                    {
                                        filename = bs.GetValue("newFileName") + "_" + channelName;
                                    }
                                    else
                                    {
                                        filename = batchImg.deaultName + "_" + channelName;
                                    }

                                    // Generate a full path based on name + directory
                                    filePath = fileDir + "\\" + filename + "." + expFormat.ToString();
                                    // imgExportChannels[i].Save(filePath, expFormat);
                                    SaveImage(filePath, imgExportChannels[i], expFormat);
                                }
                                else
                                {
                                    imgExportChannels[i] = null; // This array position will be null
                                }
                            }
                        }
                    }
                    UpdatePicbox(listLoadedImg[curImgIndex]);
                }
                else
                {
                    // If anything other than OK is selected, clear all the image previews
                    foreach (LoadedImage img in listLoadedImg)
                    {
                        img.ClearPreview();
                    }
                }
                // Update the loaded picturebox window, in case there were any changes.
                //UpdatePicbox(listLoadedImg[curImgIndex]);
            }
        }
Example #2
0
        // Utilises the Batch dialog window to export, rename, apply file types to files AFTER processing
        private void BatchFileProcess()
        {
            using (BatchSettings dlgBatch = new BatchSettings())
            {
                if (dlgBatch.ShowDialog() == DialogResult.OK)
                {
                    // If exporting is not turned on
                    if (dlgBatch.export == false)
                    {
                        // nowt
                    }
                    // If it IS turned on
                    else
                    {
                        // If isBypassing dialog is not activated
                        if (dlgBatch.bypass == false)
                        {
                            foreach (LoadedImage img in listLoadedImg)
                            {
                                using (SaveFileDialog dlgSave = new SaveFileDialog())
                                {
                                    dlgSave.FileName = img.GetName();
                                    dlgSave.InitialDirectory = "C:/Desktop";
                                    dlgSave.Filter = "JPEG Image|*.jpg|BMP Image|*.bmp|PNG Image|*.png|TIFF Image|*.tiff";
                                    dlgSave.Title = "Save Your Image";

                                    if (dlgSave.ShowDialog() == DialogResult.OK)
                                    {
                                        SaveImage(dlgSave, img.GetBitmap("c"));
                                    }
                                }
                            }
                        }
                        // if it IS turned on
                        else
                        {
                            string filename = null;
                            ImageFormat format = null;

                            // Applying the selected filetype from the dlgBatch using an index. THIS REQUIRES THAT THE INDICIES MATCH the cases below
                            switch (dlgBatch.fileType)
                            {
                                case 0:
                                    format = ImageFormat.Jpeg;
                                    break;
                                case 1:
                                    format = ImageFormat.Bmp;
                                    break;
                                case 2:
                                    format = ImageFormat.Png;
                                    break;
                                case 3:
                                    format = ImageFormat.Tiff;
                                    break;
                            }

                            for (int i = 0; i < listLoadedImg.Count(); i++)
                            {
                                if (dlgBatch.rename == true)
                                {
                                    string path = Path.GetDirectoryName(dlgBatch.fileName) + "\\" + Path.GetFileNameWithoutExtension(dlgBatch.fileName) + "_grayscale_" + i + Path.GetExtension(dlgBatch.fileName);
                                    filename = path;
                                }
                                else
                                    filename = (listLoadedImg[curImgIndex].GetDefaultDir() + "\\" + listLoadedImg[i].GetName() + "_Grayscale" + dlgBatch.fileTypeString);

                                listLoadedImg[i].GetBitmap("c").Save(filename, format);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        // Apply the current set of effects from the BatchSettings window
        // In all instances, the previewVer of the image is being updated, so the effects will stack
        public void ApplyBatchSettingsEffects(BatchSettings bs, LoadedImage img)
        {
            // Initially set previewVer to match currentVer, start from plain image as opposed to previous preview effects
            img.UpdatePreview(img.GetBitmap("c"));

            // TRANSFORMS
            // Scale
            if (bs.arrChkOptions[1][0].Checked)
            {
                img.UpdatePreview(adjustImg.GetScaledVer(img.GetBitmap("p"), bs.transformScale, bs.transformScale, true));
            }
            // Rotation
            if (bs.arrChkOptions[1][1].Checked)
            {
                img.UpdatePreview(adjustImg.GetRotatedVer(img.GetBitmap("p"), bs.transformRotation));
            }
            // Flip
            if (bs.arrChkOptions[1][2].Checked)
            {
                img.UpdatePreview(adjustImg.GetFlippedVer(img.GetBitmap("p"), bs.flipV, bs.flipH));
            }

            // FILTERS
            int filterToApply = -1;
            for (int i = 0; i < bs.arrChkOptions[3].Length; i++)
            {
                // If a filter is found checked, stop and begin to work on it.
                if (bs.arrChkOptions[3][i].Checked)
                {
                    filterToApply = i;
                    break;
                }
            }

            // If a filter was found checked
            if (filterToApply != -1)
            {
                switch (filterToApply)
                {
                    case 0: // Sepia
                        {
                            // Get current bitmap, apply sepia and place in the preview slot of the loadedimg
                            img.UpdatePreview(adjustImg.GetSepia(img.GetBitmap("p")));
                        }
                        break;
                    case 1: // Grayscale
                        {
                            // tmp for readability. Apply Grayscale (with algorithm string from bs) to current version
                            Bitmap tmp = adjustImg.GetGrayscale(img.GetBitmap("p"), bs.grayAlgorithm);
                            // Then apply to preview slot
                            img.UpdatePreview(tmp);
                        }
                        break;
                    default:
                        {
                            Environment.Exit(25);
                        }
                        break;
                }
            }

            // ADJUSTMENTS

            // Transparency
            if (bs.arrChkOptions[2][0].Checked == true)
            {
                // The byte value is necessary for the image adjustment
                byte amount = bs.transpInput;
                // tmp for readability,
                Bitmap tmp = adjustImg.GetTransparent(img.GetBitmap("p"), amount);
                img.UpdatePreview(tmp);
            }
        }
        private void manuBatch_Click(object sender, EventArgs e)
        {
            using (BatchSettings bs = new BatchSettings(this))
            {
                // Apply effects only to previewVer of each image
                if (bs.ShowDialog() != DialogResult.Cancel)
                {
                    // Distinguish collection, which images to apply Batching to?
                    // bs.arrIsProcessed;

                    for (int i = 0; i < listLoadedImg.Count; i++)
                    {
                        // Is the image at this index is to be processed.
                        if (bs.arrIsProcessed[i] == true)
                        {

                            listLoadedImg[i].previewVer = listLoadedImg[i].GetBitmap("c");
                        }
                    }

                    // Work through adjustments

                    // Work through filters

                    // Utilise fileExport options

                    foreach (LoadedImage img in listLoadedImg)
                    {
                        // UpdateImg(previewVer), clear previewVer
                    }
                }
            }
        }