Example #1
0
        private void cbxResizeType_SelectedIndexChanged(object sender, EventArgs e)
        {
            int  resizeValue = 0;
            bool success     = MediaProcessorOptions.TryParseResizeValue(this.txtResize.Text, (comboOptions)this.comboLastIdx, out resizeValue);

            if (!success)
            {
                this.comboTxtDefaults[this.comboLastIdx] = resizeValue;
            }
            this.txtResize.Text = this.comboTxtDefaults[this.cbxResizeType.SelectedIndex].ToString();
            this.comboLastIdx   = this.cbxResizeType.SelectedIndex;
        }
Example #2
0
        private bool TryReadDefaultCropRatio(out float?defaultCropRatio)
        {
            bool success = true;

            defaultCropRatio = null;
            if (this.txtRatio1.Text.Length > 0 && this.txtRatio2.Text.Length > 0)
            {
                float cropRatio;
                success = MediaProcessorOptions.TryParseCropRatio(this.txtRatio1.Text + ":" + this.txtRatio2.Text, out cropRatio);
                if (success)
                {
                    defaultCropRatio = cropRatio;
                }
            }
            return(success);
        }
Example #3
0
        private void btnProcess_Click(object sender, EventArgs e)
        {
            if (MP.isProcessing)
            {
                this.cancelSource.Cancel();
                return;
            }
            if (MP.GetNumFiles() == 0)
            {
                MessageBox.Show("No files selected.", "No files selected", MessageBoxButtons.OK);
                return;
            }
            int  resizeValue = 0;
            bool success     = MediaProcessorOptions.TryParseResizeValue(this.txtResize.Text, (comboOptions)this.cbxResizeType.SelectedIndex, out resizeValue);

            if (!success)
            {
                MessageBox.Show("Invalid value entered for resizing images to.", "Invalid entry", MessageBoxButtons.OK);
                return;
            }
            int videoResizeValue = 0;

            success = MediaProcessorOptions.TryParseResizeValue(this.txtVideoResize.Text, (comboOptions)this.cbxVideoResizeType.SelectedIndex, out videoResizeValue);
            if (!success)
            {
                MessageBox.Show("Invalid value entered for resizing videos to.", "Invalid entry", MessageBoxButtons.OK);
                return;
            }

            success = this.TryReadDefaultCropRatio(out float?defaultCropRatio);
            if (!success)
            {
                MessageBox.Show("Invalid value entered for crop ratio.", "Invalid entry", MessageBoxButtons.OK);
                return;
            }

            MediaProcessorOptions options = new MediaProcessorOptions(
                (comboOptions)this.cbxResizeType.SelectedIndex,
                (comboOptions)this.cbxVideoResizeType.SelectedIndex,
                (outTypeOptions)this.cbxOutputType.SelectedIndex,
                (videoOutTypeOptions)this.cbxVideoOutputType.SelectedIndex,
                resizeValue,
                videoResizeValue,
                (int)nudQuality.Value,
                (int)nudVideoQuality.Value,
                defaultCropRatio
                );

            MP.SetOptions(options);
            MP.SetFileSuffix(txtSuffix.Text);

            FileValidationResult val = MP.ValidateFileList();

            if (val.noInputList.Count > 0 || val.folderFailedList.Count > 0)
            {
                MessageBox.Show(val.message, "Invalid file list", MessageBoxButtons.OK);
                return;
            }
            if (val.outputExistsList.Count > 0)
            {
                DialogResult res = MessageBox.Show("Overwrite these files?\r\n\r\n" + val.message, "Files already exist", MessageBoxButtons.YesNo);
                if (res == DialogResult.No)
                {
                    return;
                }
            }

            CancellationToken token = this.cancelSource.Token;

            this.OnProcessingStart();
            Task processingTask = Task.Factory.StartNew(() =>
            {
                MP.Run(token, UpdateOnProgress);
                if (token.IsCancellationRequested)
                {
                    this.OnProcessingCancelled();
                }
                else
                {
                    this.OnProcessingComplete(MP.GetResult());
                }
            }, token);
        }