System.Drawing.PieChart.ColorUtil.CreateColorWithCorrectedLightness C# (CSharp) Method

CreateColorWithCorrectedLightness() public static method

Creates color with corrected lightness.
public static CreateColorWithCorrectedLightness ( System.Color color, float correctionFactor ) : System.Color
color System.Color /// Color to correct. ///
correctionFactor float /// Correction factor, with a value between -1 and 1. Negative values /// create darker color, positive values lighter color. Zero value /// returns the current color. ///
return System.Color
        public static Color CreateColorWithCorrectedLightness(Color color, float correctionFactor)
        {
            Debug.Assert(correctionFactor <= 1 && correctionFactor >= -1);
            if (correctionFactor == 0)
                return color;
            float red   = (float)color.R;
            float green = (float)color.G;
            float blue  = (float)color.B;
            if (correctionFactor < 0) {
                correctionFactor = 1 + correctionFactor;
                red   *= correctionFactor;
                green *= correctionFactor;
                blue  *= correctionFactor;
            }
            else {
                red   = (255 - red) * correctionFactor + red;
                green = (255 - green) * correctionFactor + green;
                blue  = (255 - blue) * correctionFactor + blue;
            }
            return System.Drawing.Color.FromArgb(color.A, (int)red, (int)green, (int)blue);
        }

Usage Example

示例#1
0
        /// <summary>
        ///   Gets the actual color used for rendering.
        /// </summary>
        public static Color GetRenderingColor(EdgeColorType edgeColorType, Color color)
        {
            Debug.Assert(color != Color.Empty);
            if (edgeColorType == EdgeColorType.Contrast || edgeColorType == EdgeColorType.EnhancedContrast)
            {
                edgeColorType = GetContrastColorType(color, edgeColorType);
            }
            float correctionFactor = 0;

            switch (edgeColorType)
            {
            case EdgeColorType.SystemColor:
                return(SystemColors.WindowText);

            case EdgeColorType.SurfaceColor:
                return(color);

            case EdgeColorType.FullContrast:
                return(GetFullContrastColor(color));

            case EdgeColorType.DarkerThanSurface:
                correctionFactor = -ColorUtil.BrightnessEnhancementFactor1;
                break;

            case EdgeColorType.DarkerDarkerThanSurface:
                correctionFactor = -ColorUtil.BrightnessEnhancementFactor2;
                break;

            case EdgeColorType.LighterThanSurface:
                correctionFactor = +ColorUtil.BrightnessEnhancementFactor1;
                break;

            case EdgeColorType.LighterLighterThanSurface:
                correctionFactor = +ColorUtil.BrightnessEnhancementFactor2;
                break;

            case EdgeColorType.NoEdge:
                return(System.Drawing.Color.Transparent);
            }
            return(ColorUtil.CreateColorWithCorrectedLightness(color, correctionFactor));
        }
All Usage Examples Of System.Drawing.PieChart.ColorUtil::CreateColorWithCorrectedLightness