public static RGBA GetBestForegroundColor(this RGBA color) { return(color.Luminance() > rgbThreshold ? RGBA.Black : RGBA.White); //return (color.Red * 0.299 + color.Green * 0.587 + color.Blue * 0.114 > 160) ? RGBA.White : RGBA.Black; }
public static double Luminance(this RGBA color) { return(Luminance(color.Red, color.Green, color.Blue)); }
/// <summary> /// Gets the best foreground color given the specified background color. /// </summary> /// <param name="color">The background color.</param> /// <returns>The best <see cref="RGBA"/> foreground color.</returns> public static RGBA GetBestForegroundColor(this RGBA color) { return(color.Luminance() > rgbThreshold ? RGBA.Black : RGBA.White); }