public MainForm()
        {
            InitializeComponent();

            var executingAssembly = Assembly.GetExecutingAssembly();

            Icon  = Icon.ExtractAssociatedIcon(executingAssembly.Location);
            Text += $" - {executingAssembly.GetName().Version}";

            _openFileDialog = new OpenFileDialog()
            {
                CheckFileExists = true,
                CheckPathExists = true,
            };

            _saveFileDialog = new SaveFileDialog()
            {
                DefaultExt      = ".png",
                Filter          = "Bitmap|*.bmp|Jpeg|*.jpg|Png|*.png|Gif|*.gif|All files|*.*",
                FilterIndex     = 3, // 1 based
                OverwritePrompt = true,
            };

            _ffmpegWrapper  = new FfmpegWrapper("ffmpeg.exe");
            _imageProcessor = new ImageProcessor();

            useInputHeightForOutputCheckBox.Checked = true;
            generateButton.Text = GenerateButtonText;
        }
Beispiel #2
0
        public (Bitmap, string) CreateBarCode(
            string inputPath,
            FfmpegWrapper ffmpeg,
            CancellationToken cancellationToken,
            IProgress <double> progress = null)
        {
            Bitmap   finalBitmap         = null;
            Graphics finalBitmapGraphics = null;

            Graphics GetDrawingSurface(int width, int height)
            {
                if (finalBitmap == null)
                {
                    finalBitmap         = new Bitmap(width, height);
                    finalBitmapGraphics = Graphics.FromImage(finalBitmap);
                }
                return(finalBitmapGraphics);
            }

            var barCount = (int)Math.Round((double)SettingsHandler.ImageWidth / SettingsHandler.BarWidth);

            var audioPath = Path.ChangeExtension(Path.GetFileName(inputPath), "wav");

            audioPath = Path.Combine(SettingsHandler.OutputDir, audioPath.Replace(" ", ""));

            var source = ffmpeg.GetImagesFromMedia(inputPath, audioPath, barCount, cancellationToken);

            int?finalBitmapHeight = null;

            int x = 0;

            foreach (var image in source)
            {
                if (finalBitmapHeight == null)
                {
                    finalBitmapHeight = SettingsHandler.ImageHeight ?? image.Height;
                }

                var surface = GetDrawingSurface(SettingsHandler.ImageWidth, finalBitmapHeight.Value);
                surface.DrawImage(image, x, 0, SettingsHandler.BarWidth, finalBitmapHeight.Value);

                x += SettingsHandler.BarWidth;

                progress?.Report((double)x / SettingsHandler.ImageWidth);

                image.Dispose();
            }

            finalBitmapGraphics?.Dispose();

            return(finalBitmap, audioPath);
        }
        public Bitmap CreateBarCode(
            string inputPath,
            BarCodeParameters parameters,
            FfmpegWrapper ffmpeg,
            CancellationToken cancellationToken,
            IProgress <double> progress = null)
        {
            Bitmap   finalBitmap         = null;
            Graphics finalBitmapGraphics = null;

            Graphics GetDrawingSurface(int width, int height)
            {
                if (finalBitmap == null)
                {
                    finalBitmap         = new Bitmap(width, height);
                    finalBitmapGraphics = Graphics.FromImage(finalBitmap);
                }
                return(finalBitmapGraphics);
            }

            var barCount = (int)Math.Round((double)parameters.Width / parameters.BarWidth);
            var source   = ffmpeg.GetImagesFromMedia(inputPath, barCount, cancellationToken);

            int?finalBitmapHeight = null;

            int x = 0;

            foreach (var image in source)
            {
                if (finalBitmapHeight == null)
                {
                    finalBitmapHeight = parameters.Height ?? image.Height;
                }

                var surface = GetDrawingSurface(parameters.Width, finalBitmapHeight.Value);
                surface.DrawImage(image, x, 0, parameters.BarWidth, finalBitmapHeight.Value);

                x += parameters.BarWidth;

                progress?.Report((double)x / parameters.Width);

                image.Dispose();
            }

            finalBitmapGraphics?.Dispose();

            return(finalBitmap);
        }
Beispiel #4
0
        public MainForm()
        {
            InitializeComponent();

            var executingAssembly = Assembly.GetExecutingAssembly();

            Icon  = Icon.ExtractAssociatedIcon(executingAssembly.Location);
            Text += $" - {executingAssembly.GetName().Version}";


            AudioProcessor.Init(); // clear logfile
            SettingsHandler.Load();
            imageHeightTextBox.ReadOnly = SettingsHandler.UseInputHeight;
            barCountTextBox.Text        = SettingsHandler.BarCount.ToString();
            smoothCheckBox.Checked      = SettingsHandler.ShouldCreateSmoothDuplicate;
            chunkSizeTextBox.Text       = SettingsHandler.ChunkSize.ToString();
            fileCountProgress.Visible   = false;

            _sourceFolderDialog.RootFolder = Environment.SpecialFolder.Desktop;
            _targetFolderDialog            = new FolderBrowserDialog();



            if (!string.IsNullOrEmpty(SettingsHandler.SourceDir))
            {
                _targetFolderDialog.SelectedPath = SettingsHandler.SourceDir;
                inputPathTextBox.Text            = SettingsHandler.SourceDir;
            }
            if (!string.IsNullOrEmpty(SettingsHandler.OutputDir))
            {
                _sourceFolderDialog.SelectedPath = SettingsHandler.OutputDir;
                outputPathTextBox.Text           = SettingsHandler.OutputDir;
            }



            #region find python

            if (!string.IsNullOrEmpty(SettingsHandler.PythonExe))
            {
                _locatePythonDialog.FileName = SettingsHandler.PythonExe;
                pythonLocTextBox.Text        = SettingsHandler.PythonExe;
            }
            else
            {
                _locatePythonDialog.FileName = "";
            }

            string pythonPath = Directory.GetDirectories("C:\\", "Python3*").FirstOrDefault();
            if (string.IsNullOrEmpty(pythonPath))
            {
                pythonPath = Directory.GetDirectories("C:\\Program Files\\", "Python3*").FirstOrDefault();
            }
            if (string.IsNullOrEmpty(pythonPath))
            {
                pythonPath = Path.Combine("%AppData%", "Local\\Programs");
            }

            _locatePythonDialog.InitialDirectory = pythonPath;
            #endregion

            _ffmpegWrapper  = new FfmpegWrapper("ffmpeg.exe");
            _imageProcessor = new ImageProcessor();

            useInputHeightForOutputCheckBox.Checked = true;
            generateButton.Text = GenerateButtonText;
        }