I'm calling multiple color correction methods from a pictureBox click event. The problem is, sometimes a method will be skipped. Sometimes a method will run twice. So I may not be using the best possible way to call my methods. Code follows:
EDIT: I received a comment stating that the question is unclear. It seems clear to me. But in case I'm wrong, let me clarify: I am getting errors with my current way of calling multiple methods. What is the proper way to do so?
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox0.Image = pictureBox1.Image;
foreach (PictureBox item in Controls.OfType<PictureBox>())
{
item.Image = pictureBox0.Image;
item.Refresh();
}
runColorMethods();
}
private void runColorMethods()
{
red();
orange();
yellow();
green();
blue();
magenta();
}
It would take too much space to show all six methods, one will suffice.
private void red()
{
// declare initial variables
int xRed = 32;
lock (lockObject)
{
// Get bitmap from picturebox
Bitmap bmp1 = (Bitmap)pictureBox1.Image;
// search through each pixel via x, y coordinates, examine and make changes.
// Dont let values exceed 255 or fall under 0.
for (int y = 0; y < bmp1.Height; y++)
for (int x = 0; x < bmp1.Width; x++)
{
Color c = bmp1.GetPixel(x, y);
int myRed = c.R, myGreen = c.G, myBlue = c.B;
myRed += xRed;
if (myRed > 255)
myRed = 255;
bmp1.SetPixel(x, y, Color.FromArgb(255, myRed, myGreen, myBlue));
}
// assign the new bitmap to the picturebox
pictureBox1.Image = (Bitmap)bmp1;
}
}
I've heard of multicast delegates being used to call multiple methods, but I do not know how to use them correctly, or if they are even the best way to go. Recommendations?