Invert an image is like to view the negative of an image. With this method you will be able to control the degree of transparency with the alpha variable
Code: Select all
/// <summary>
/// Inverts an Image with the option to Invert it's Transparency.
/// </summary>
/// <param name="bitmap">The Bitmap Image you want to Invert.</param>
/// <param name="InvertAlpha">True to Invert it's Transparency. False to Invert the Image Only.</param>
/// <returns>An Inverted Image</returns>
public Bitmap Invert(Bitmap bitmap)
{
//X Axis
int x;
//Y Axis
int y;
//For the Width
for (x = 0; x <= bitmap.Width - 1; x++)
{
//For the Height
for (y = 0; y <= bitmap.Height - 1; y += 1)
{
//The Old Color to Replace
Color oldColor = bitmap.GetPixel(x, y);
//The New Color to Replace the Old Color
Color newColor;
//Set the Color for newColor
newColor = Color.FromArgb(oldColor.A, 255 - oldColor.R, 255 - oldColor.G, 255 - oldColor.B);
//Replace the Old Color with the New Color
bitmap.SetPixel(x, y, newColor);
}
}
//Return the Inverted Bitmap
return bitmap;
}
/// <summary>
/// Inverts an Image with the option to Invert it's Transparency.
/// </summary>
/// <param name="bitmap">The Bitmap Image you want to Invert.</param>
/// <param name="InvertAlpha">True to Invert it's Transparency. False to Invert the Image Only.</param>
/// <returns>An Inverted Image</returns>
public Bitmap Invert(Bitmap bitmap, bool InvertAlpha)
{
//X Axis
int x;
//Y Axis
int y;
//For the Width
for (x = 0; x <= bitmap.Width - 1; x++)
{
//For the Height
for (y = 0; y <= bitmap.Height - 1; y += 1)
{
//The Old Color to Replace
Color oldColor = bitmap.GetPixel(x, y);
//The New Color to Replace the Old Color
Color newColor;
//If the user has chosen to Invert the Transparency
if (InvertAlpha)
{
//Set the Color for newColor
newColor = Color.FromArgb(255 - oldColor.A, 255 - oldColor.R, 255 - oldColor.G, 255 - oldColor.B);
}
else
{
//Set the Color for newColor
newColor = Color.FromArgb(oldColor.A, 255 - oldColor.R, 255 - oldColor.G, 255 - oldColor.B);
}
//Replace the Old Color with the New Color
bitmap.SetPixel(x, y, newColor);
}
}
//Return the Inverted Bitmap
return bitmap;