Tuesday, January 09, 2007

A function to calculate the opposite color of given color

/// <summary>
/// Calculates the opposite color
/// </summary>
/// <param name="clr">Given color</param>
/// <returns></returns>
public static Color CalculateOppositeColor(Color clr)
{
return Color.FromArgb(255 - clr.R, 255 - clr.G, 255 - clr.B);
}

3 comments:

  1. yeh cheers for this!

    ReplyDelete
  2. Well, not a good idea. One can see it in some programs when the background is gray (128, 128, 128) - then the opposite color would be 127,127,127 - for the human eye is impossible to distinguish. The marker or selection box is lost agaist the gray background.

    ReplyDelete