private async void ButtonMinesweeperizeImage_Click(object sender, RoutedEventArgs e) { if (imagesFilepaths.Count == 0) { labelInfo.Content = "Choose images to process."; return; } addFrame = (bool)CheckBoxAddFrame.IsChecked; flags = comBoxFlag.SelectedIndex; if (!Int32.TryParse(textBoxHeight.Text, out height) || !Int32.TryParse(textBoxSize.Text, out squareSize) || height < 1 || squareSize < 1) { labelInfo.Content = "Incorrect height or size value."; return; } if (!Int32.TryParse(textBoxTreshold.Text, out treshold)) { labelInfo.Content = "Incorrect threshold value."; return; } if (!LoadGraphics()) { labelInfo.Content = "Can't find all pictures of " + ((ComboBoxItem)comboBoxChooseStyle.SelectedItem).Content.ToString() + " theme."; return; } ChangeRelevantButtonState(false); for (int i = 0; i < imagesFilepaths.Count; i++) { labelInfo.Content = "Processing file " + (i + 1).ToString() + " of " + imagesFilepaths.Count.ToString() + "."; await Task.Run(() => { Bitmap output = MinesweeperizerClass.Minesweeperize(new Bitmap(imagesFilepaths[i]), squares, squareSize, treshold, height, flags, addFrame); output.Save(imagesFilepaths[i].Remove(imagesFilepaths[i].Length - Path.GetExtension(imagesFilepaths[i]).Length) + " (minesweeperized)" + ".png", ImageFormat.Png); }); ((IProgress <float>)progressConverting).Report(100 * i / imagesFilepaths.Count); } labelInfo.Content = "Done!"; ((IProgress <float>)progressConverting).Report(0); ChangeRelevantButtonState(true); }
private void Minesweeperize(string ImageLocation) { Bitmap output = MinesweeperizerClass.Minesweeperize(new Bitmap(ImageLocation), squares, squareSize, treshold, height, flags, addFrame); output.Save(ImageLocation.Remove(ImageLocation.Length - Path.GetExtension(ImageLocation).Length) + " (minesweeperized)" + ".png", ImageFormat.Png); }
private async void MinesweeperizeVideo() { ChangeRelevantButtonState(false); labelInfo.Content = "Cleaning temporaryCatalog..."; double fps = 0; await Task.Run(() => { DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\minesweeperizer\\temporaryCatalog"); foreach (FileInfo file in di.EnumerateFiles()) { file.Delete(); } }); labelInfo.Content = "Reading fps info..."; await Task.Run(() => { var p = new Process { StartInfo = new ProcessStartInfo { WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\minesweeperizer\\", FileName = ffmpeg, Arguments = " -i \"" + videoFilepath + "\"", UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true } }; try { p.Start(); } catch (Exception e) { WindowFFMPEG w = new WindowFFMPEG(); w.ShowDialog(); p.StartInfo.FileName = ffmpeg; p.Start(); } String line = p.StandardError.ReadToEnd(); line = System.Text.RegularExpressions.Regex.Match(line, $", [0-9.]+? fps,").Value; line = line.Remove(line.Length - 5); line = line.Substring(2, line.Length - 2); p.WaitForExit(); fps = Double.Parse(line); }); labelInfo.Content = "Extracting frames from video..."; await Task.Run(() => { ProcessStartInfo pExtract = new ProcessStartInfo { WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\minesweeperizer\\", FileName = ffmpeg, Arguments = " -i \"" + videoFilepath + "\" temporaryCatalog\\%05d.png" }; Process.Start(pExtract).WaitForExit(); }); List <string> videoImagesFilepaths = new List <string>(Directory.GetFiles("minesweeperizer\\temporaryCatalog")); leftNumber = 0; rightNumber = 0; for (int i = 0; i < videoImagesFilepaths.Count; i++) { leftNumber++; rightNumber = leftNumber / (int)(Math.Round(fps)); labelInfo.Content = "Processing image " + (i + 1).ToString() + " of " + videoImagesFilepaths.Count.ToString() + "."; await Task.Run(() => { Bitmap output = MinesweeperizerClass.Minesweeperize(new Bitmap(videoImagesFilepaths[i]), squares, squareSize, treshold, height, flags, addFrame, leftNumber, rightNumber); output.Save(videoImagesFilepaths[i].Remove(videoImagesFilepaths[i].Length - Path.GetExtension(videoImagesFilepaths[i]).Length) + " (minesweeperized)" + ".png", ImageFormat.Png); }); ((IProgress <float>)progressConverting).Report(100 * i / videoImagesFilepaths.Count); } labelInfo.Content = "Rendering video..."; await Task.Run(() => { ProcessStartInfo pCompile = new ProcessStartInfo { WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\minesweeperizer\\", FileName = ffmpeg, Arguments = "-framerate " + fps.ToString() + " -i \"temporaryCatalog\\%05d (minesweeperized).png\" -i \"" + videoFilepath + "\" -c:a copy -c:v libx264 \"" + videoFilepath.Remove(videoFilepath.Length - 5, 4) + " (minesweeperized).mp4\"" }; Process.Start(pCompile).WaitForExit(); }); labelInfo.Content = "Done."; ((IProgress <float>)progressConverting).Report(0); ChangeRelevantButtonState(true); }