private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (_img != null) { var filter = comboBox1.SelectedItem.ToString(); switch (filter) { case "Negative": _filter = filter.ToLower(); var negative = new NegativeImage(_img); _newImg = negative.AddNegativeFilter(); ShowImage(_newImg); break; case "Grayscale": _filter = filter.ToLower(); var grayscale = new GrayscaleImage(_img); _newImg = grayscale.AddGrayscaleFilter(); ShowImage(_newImg); break; case "Blurred": _filter = filter.ToLower(); var blur = new BlurredImage(_img); _newImg = blur.AddBlurFilter(); ShowImage(_newImg); break; } } else { MessageBox.Show("No image has been selected, please select an image for continuing", "No Image", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static string Process(string str) { var message = ""; var valid = true; Bitmap img = null; string path = null; try { path = str; img = new Bitmap(path); } catch (FileNotFoundException) { return("Something was wrong with the input, Please try again"); } catch (IndexOutOfRangeException) { return("Something was wrong with the input, Please try again"); } catch (ArgumentException) { return("Something was wrong with the input, Please try again"); } if (valid && img != null && path != null) { if (!FileHandler.CheckPath(path)) { return("Something was wrong with the input, Please try again"); } // Check if size is over 400x400 = 160 000 else if (!FileHandler.CheckImageSize(img)) { return("The image you have entered is too big, Please enter a smaller one"); } else { // Create and save a negative image var negative = new NegativeImage(img); var negativeImage = negative.AddNegativeFilter(); negativeImage.Save(FileHandler.GetNewPath(path, "_negative")); // Create and save a grayscale image var grayscale = new GrayscaleImage(img); var grayscaleImage = grayscale.AddGrayscaleFilter(); grayscaleImage.Save(FileHandler.GetNewPath(path, "_grayscale")); // Create and save a blurred image var blurred = new BlurredImage(img); var blurredImage = blurred.AddBlurFilter(); blurredImage.Save(FileHandler.GetNewPath(path, "_blurred")); // If everything works, exit the application Environment.Exit(0); } } return(message); }
public void AddBlurFilter_FilterAdded_ColorsBlurred() { // Arrange const int width = 3; const int height = 3; var img = new Bitmap(width, height); var expectedImg = new Bitmap(width, height); for (var x = 0; x < img.Width; x++) { for (var y = 0; y < img.Height; y++) { const int alpha = 255; var val = 255; if (y % 2 == 0) { val = 0; } img.SetPixel(x, y, Color.FromArgb(alpha, val, val, val)); } } for (var x = 0; x < expectedImg.Width; x++) { for (var y = 0; y < expectedImg.Height; y++) { var expected = 85; expectedImg.SetPixel(x, y, Color.FromArgb(255, expected, expected, expected)); } } // Act var blurred = new BlurredImage(img); var blurredImage = blurred.AddBlurFilter(); // Assert for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { Assert.AreEqual(expectedImg.GetPixel(x, y).A, blurredImage.GetPixel(x, y).A); Assert.AreEqual(expectedImg.GetPixel(x, y).R, blurredImage.GetPixel(x, y).R); Assert.AreEqual(expectedImg.GetPixel(x, y).G, blurredImage.GetPixel(x, y).G); Assert.AreEqual(expectedImg.GetPixel(x, y).B, blurredImage.GetPixel(x, y).B); } } }