private Bitmap MakeScale(Bitmap original, MakeColorDelegate makeColor) { /* * The MakeScale function will iterate through the bitmap computing * a new value for the pixel with a given filter. The filter is pass * in by the makeColor delegate. The given delegate will point to one * of the MakeColorScales which will alter the color for the given pixel. */ try { Bitmap newBitmap = new Bitmap(original.Width, original.Height); for (int i = 0; i < original.Width; i++) { for (int j = 0; j < original.Height; j++) { Color newColor = makeColor(original, i, j); newBitmap.SetPixel(i, j, newColor); } } return(newBitmap); } catch (Exception ex) { throw new NotImplementedException(); } }
private void ColorClick(MakeColorDelegate colorDelegate) { /* * A general template for the click color buttons that generates a new * form and display a filtered image. */ Form newForm = new Scale(); // Create a new form Bitmap imageInstance = (Bitmap)OpenImageDisplay.Image; // Grab the image inside the PictureBox Bitmap newInstance = new Bitmap(imageInstance.Width, imageInstance.Height); // Create a new Bitmap that is the same size as the image if (imageInstance != null) { newInstance = MakeScale(imageInstance, colorDelegate); // Apply the filter Generate_TempPict(newForm, newInstance); } }
private Bitmap ScanImage(Bitmap newImage, int[,] verticalFilter, int[,] horizontalFilter, int[,] diagonalFilter) { int pixel; Bitmap original = (Bitmap)(OpenImageDisplay.Image); Bitmap newBitmap = new Bitmap(original.Width, original.Height); MakeColorDelegate grayDelegate = new MakeColorDelegate(MakeGrayScale); Bitmap grayBitmap = MakeScale(Pad_Bitmap((Bitmap)OpenImageDisplay.Image), grayDelegate); for (int i = 2; i < grayBitmap.Width - 2; i++) { for (int j = 2; j < grayBitmap.Height - 2; j++) { int[,] pixelnxn; if (verticalFilter.Length == 9) { pixelnxn = new int[3, 3] { { grayBitmap.GetPixel(i - 1, j - 1).G, grayBitmap.GetPixel(i - 0, j - 1).G, grayBitmap.GetPixel(i + 1, j - 1).G }, { grayBitmap.GetPixel(i - 1, j - 0).G, grayBitmap.GetPixel(i - 0, j - 0).G, grayBitmap.GetPixel(i + 1, j - 0).G }, { grayBitmap.GetPixel(i - 1, j + 1).G, grayBitmap.GetPixel(i - 0, j + 1).G, grayBitmap.GetPixel(i + 1, j + 1).G } }; } else { pixelnxn = new int[2, 2] { { grayBitmap.GetPixel(i - 1, j - 1).G, grayBitmap.GetPixel(i - 0, j - 1).G }, { grayBitmap.GetPixel(i - 1, j - 0).G, grayBitmap.GetPixel(i - 0, j - 0).G }, }; } pixel = Calculate_Pixel_Distance(pixelnxn, verticalFilter, horizontalFilter, diagonalFilter); Color newColor = Color.FromArgb(pixel, pixel, pixel); newBitmap.SetPixel(i - 2, j - 2, newColor); } } return(newBitmap); }
private void Cb_Click(object sender, EventArgs e) { MakeColorDelegate cbDelegate = new MakeColorDelegate(MakeCbScale); ColorClick(cbDelegate); }
private void Q_Click(object sender, EventArgs e) { MakeColorDelegate qDelegate = new MakeColorDelegate(MakeQScale); ColorClick(qDelegate); }
private void I_Click(object sender, EventArgs e) { MakeColorDelegate iDelegate = new MakeColorDelegate(MakeIScale); ColorClick(iDelegate); }
private void V_Click(object sender, EventArgs e) { MakeColorDelegate vDelegate = new MakeColorDelegate(MakeVScale); ColorClick(vDelegate); }
private void U_Click(object sender, EventArgs e) { MakeColorDelegate uDelegate = new MakeColorDelegate(MakeUScale); ColorClick(uDelegate); }
private void Blue_Click(object sender, EventArgs e) { MakeColorDelegate blueDelegate = new MakeColorDelegate(MakeBlueScale); ColorClick(blueDelegate); }
private void Green_Click(object sender, EventArgs e) { MakeColorDelegate greenDelegate = new MakeColorDelegate(MakeGreenScale); ColorClick(greenDelegate); }
private void Red_Click(object sender, EventArgs e) { MakeColorDelegate redDelegate = new MakeColorDelegate(MakeRedScale); ColorClick(redDelegate); }
/* * All Color Click methods operate the same way. It method will begin by * creating a delegate that points to a MakeColor function. We will then * run ColorClick method with the given delegate. */ private void Gray_Scale_Click(object sender, EventArgs e) { MakeColorDelegate grayDelegate = new MakeColorDelegate(MakeGrayScale); ColorClick(grayDelegate); }