private void bt_resize_Click(object sender, RoutedEventArgs e) { //Src checks if (string.IsNullOrWhiteSpace(tb_src.Text)) { MessageBox.Show("Source must not be empty", "Wrong path", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!Directory.Exists(tb_src.Text)) { MessageBox.Show("Source directory does not exist", "Wrong path", MessageBoxButton.OK, MessageBoxImage.Warning); return; } //Dest checks if (string.IsNullOrWhiteSpace(tb_dest.Text)) { MessageBox.Show("Destination must not be empty", "Wrong path", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!Directory.Exists(tb_dest.Text)) { MessageBox.Show("Destination directory does not exist", "Wrong path", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // path comparaisons if (cb_recursive.IsChecked == true) { if (tb_dest.Text == tb_src.Text || tb_dest.Text.Contains(tb_src.Text)) { MessageBox.Show("The destination path must not be include in source path", "Wrong path", MessageBoxButton.OK, MessageBoxImage.Warning); return; } } else { if (tb_dest.Text == tb_src.Text) { MessageBox.Show("The source path must be different from destination path", "Wrong path", MessageBoxButton.OK, MessageBoxImage.Warning); return; } } ResizerContext data = new ResizerContext(Directory.GetFiles(tb_src.Text, "*.JPG"), tb_dest.Text, tb_dest.Text, (int)slider.Value); num_file_done = 0; num_files = data.files.Length; set_ui_state(false); thread = new Thread(() => resizer.run(data)); thread.Start(); }
public void run(ResizerContext ctx) { Stream BitmapStream; System.Drawing.Image img; Bitmap image; foreach (string file in ctx.files) { using (BitmapStream = System.IO.File.Open(file, System.IO.FileMode.Open)) { using (img = System.Drawing.Image.FromStream(BitmapStream)) { using (image = new Bitmap(img)) { string filedest = System.IO.Path.Combine(ctx.dest, System.IO.Path.GetFileName(file)); if (image.Width != 3648 && image.Width != 2736) { continue; } if (image.Width == 3648) { resize(image, filedest, 1280, 960, ctx.quality); } else { resize(image, filedest, 960, 1280, ctx.quality); } } } } OnFileDone(file); } OnFinished(); }