private void mergeImagesToolStripMenuItem_Click(object sender, EventArgs e) { aboutToImageSubtract = true; tempVal = Convert.ToInt32(Prompt.ShowDialog("Enter value threshold for color subtraction. Then select a color from the first image.", "Image Subtraction")); }
private void rotateToolStripMenuItem_Click(object sender, EventArgs e) { //newX = (int)((x) * Math.Cos(rotation) + (y) * (-Math.Sin(rotation))); //newY = (int)(((x) * Math.Sin(rotation) + (y) * Math.Cos(rotation))); double rotation = Math.PI / 180 * Convert.ToDouble(Prompt.ShowDialog("How many degrees you want to rotate the image?", "Rotation")); result = new Bitmap(source.Width, source.Height); //initalize the image Color pixel; int newX, newY, transX, transY, cX, cY; for (int x = 0; x < source.Width / 2; x++) { for (int y = 0; y < source.Height / 2; y++) { //quadrant 1 pixel = source.GetPixel(x, y); newX = (int)((x - source.Width / 2) * Math.Cos(rotation) + (y - source.Height / 2) * (-Math.Sin(rotation))); newY = (int)(((x - source.Width / 2) * Math.Sin(rotation) + (y - source.Height / 2) * Math.Cos(rotation))); transX = newX + source.Width / 2; transY = newY + source.Height / 2; if (transX >= 0 && transX < source.Width && transY >= 0 && transY < source.Height) { result.SetPixel(transX, transY, pixel); } //quadrant 2 cX = source.Width / 2 + x; cY = y; pixel = source.GetPixel(cX, cY); newX = (int)((cX - source.Width / 2) * Math.Cos(rotation) + (cY - source.Height / 2) * (-Math.Sin(rotation))); newY = (int)(((cX - source.Width / 2) * Math.Sin(rotation) + (cY - source.Height / 2) * Math.Cos(rotation))); transX = newX + source.Width / 2; transY = newY + source.Height / 2; if (transX >= 0 && transX < source.Width && transY >= 0 && transY < source.Height) { result.SetPixel(transX, transY, pixel); } //quadrant 3 cX = x; cY = source.Height / 2 + y; pixel = source.GetPixel(cX, cY); newX = (int)((cX - source.Width / 2) * Math.Cos(rotation) + (cY - source.Height / 2) * (-Math.Sin(rotation))); newY = (int)(((cX - source.Width / 2) * Math.Sin(rotation) + (cY - source.Height / 2) * Math.Cos(rotation))); transX = newX + source.Width / 2; transY = newY + source.Height / 2; if (transX >= 0 && transX < source.Width && transY >= 0 && transY < source.Height) { result.SetPixel(transX, transY, pixel); } //quadrant 4 cX = source.Width / 2 + x; cY = source.Height / 2 + y; pixel = source.GetPixel(cX, cY); newX = (int)((cX - source.Width / 2) * Math.Cos(rotation) + (cY - source.Height / 2) * (-Math.Sin(rotation))); newY = (int)(((cX - source.Width / 2) * Math.Sin(rotation) + (cY - source.Height / 2) * Math.Cos(rotation))); transX = newX + source.Width / 2; transY = newY + source.Height / 2; if (transX >= 0 && transX < source.Width && transY >= 0 && transY < source.Height) { result.SetPixel(transX, transY, pixel); } } } outputPic.Image = result; }