I'm making an image-editing program in C#, and one of the functions I want to be able to have is to invert the colors.
As of currently, I have the following code which just loads the image and puts the color into a 2-d array:
if (fd.ShowDialog() == DialogResult.OK)
{
//store the selected file into a bitmap
bmp = new Bitmap(fd.FileName);
//create the arrays that store the colours for the image
//the size of the arrays is based on the height and width of the bitmap
//initially both the original and transformedPic arrays will be identical
original = new Color[bmp.Height, bmp.Width];
transformedPic = new Color[bmp.Height, bmp.Width];
//load each color into a color array
for (int i = 0; i < bmp.Height; i++)//each row
{
for (int j = 0; j < bmp.Width; j++)//each column
{
//assign the colour in the bitmap to the array
original[i, j] = bmp.GetPixel(j, i);
transformedPic[i, j] = original[i, j];
}
}
this.Refresh();
}
}
I'm completely stumped in regards to the concept of inverting colors and how I would manipulate the values in the 2-d array to reflect the inverted color of the pixel. I'm extremely new to programming, so any help would be greatly appreciated.
EDIT: (not working still)
//code to invert
byte A, R, G, B;
Color pixelColor;
for (int i = 0; i < bmp.Height; i++)
{
for (int j = 0; j < bmp.Width; j++)
{
pixelColor = original[i, j];
A = (byte)Math.Abs(255 - pixelColor.A);
R = (byte)Math.Abs(255 - pixelColor.R);
G = (byte)Math.Abs(255 - pixelColor.G);
B = (byte)Math.Abs(255 - pixelColor.B);
bmp.SetPixel(i, j, Color.FromArgb((int)A, (int)R, (int)G, (int)B));
transformedPic[i, j] = bmp.GetPixel(i, j);
}
}