System.Drawing.Color.GetSaturation C# (CSharp) Метод

GetSaturation() публичный Метод

public GetSaturation ( ) : float
Результат float
        public float GetSaturation()
        {
            float r = R / 255.0f;
            float g = G / 255.0f;
            float b = B / 255.0f;

            float s = 0;

            float max = r;
            float min = r;

            if (g > max) max = g;
            if (b > max) max = b;

            if (g < min) min = g;
            if (b < min) min = b;

            // if max == min, then there is no color and
            // the saturation is zero.
            //
            if (max != min)
            {
                float l = (max + min) / 2;

                if (l <= .5)
                {
                    s = (max - min) / (max + min);
                }
                else
                {
                    s = (max - min) / (2 - max - min);
                }
            }
            return s;
        }

Usage Example

Пример #1
0
        public int DeltaSa(Dye other)
        {
            var myS    = Color.GetSaturation();
            var otherS = other.Color.GetSaturation();

            return((int)(100 * (myS < otherS ? 1.0 + otherS - myS : 1.0 - (myS - otherS)) + 0.5));
            // ImageMagick interprets 100 as unchanged (100%), 0 is grayscale, 200 is very colorful (cartoonish)
        }
All Usage Examples Of System.Drawing.Color::GetSaturation