public freeRotateForm(Bitmap bmp) { InitializeComponent(); img=new Bitmap(bmp); origPictureBox.Image = img; newPictureBox.Image = img; helperImg = new BitmapHelper(ref img); }
//convert the image to grayscale private void convertToGrayscaleToolStripMenuItem_Click(object sender, EventArgs e) { BitmapHelper ctImage = new BitmapHelper(ref img); Pixel pixel, tmp=new Pixel(0, 0, 0 ); for (int i = 0; i < ctImage.getHeight(); i++) { for (int j = 0; j < ctImage.getWidth(); j++) { pixel = ctImage.getPixel(i, j); tmp.Blue=tmp.Green = tmp.Red = Convert.ToInt32(pixel.Red * 0.299 + pixel.Green * 0.587 + pixel.Blue * 0.114); ctImage.setPixel(i, j, tmp); } } img = ctImage.getBitmap(); origImg.Dispose(); origImg = new Bitmap(img); pictureBox.Image = img; }
//try to remove the red eyes from a selection of a picture //code logic from: http://stackoverflow.com/questions/133675/red-eye-reduction-algorithm private void redEyeReductionToolStripMenuItem_Click(object sender, EventArgs e) { BitmapHelper ctImage = new BitmapHelper(ref img); Pixel pixel; float redIntensity; //first make sure that the user selected a rectangle if (re.Height != 0 && re.Width != 0) { for (int i = re.Y; i < re.Bottom; i++) { for (int j = re.X; j < re.Right; j++) { pixel = ctImage.getPixel(i, j); //Value of red divided by average of blue and green: redIntensity = ((float)pixel.Red / ((pixel.Green + pixel.Blue) / 2)); if (redIntensity > 2.0f) { // reduce red to the average of blue and green ctImage.setPixel(i, j, new Pixel((pixel.Green + pixel.Blue) / 2, pixel.Green, pixel.Blue)); } } } img = ctImage.getBitmap(); origImg.Dispose(); origImg = new Bitmap(img); pictureBox.Image = img; } else MessageBox.Show("You must first make a selection to use this feature.", "Warning"); }
//make the image negative ( 255- R/G/B for each pixel ) private void negativeToolStripMenuItem_Click(object sender, EventArgs e) { BitmapHelper ctImage = new BitmapHelper(ref img); Pixel pixel; for (int i = 0; i < ctImage.getHeight(); i++) { for (int j = 0; j < ctImage.getWidth(); j++) { pixel = ctImage.getPixel(i, j); pixel.Red = 255 - pixel.Red; pixel.Green = 255 - pixel.Green; pixel.Blue = 255 - pixel.Blue; ctImage.setPixel(i, j, pixel); } } img = ctImage.getBitmap(); origImg.Dispose(); origImg = new Bitmap(img); pictureBox.Image = img; }