System.Drawing.Color.GetSaturation()

Here are the examples of the csharp api class System.Drawing.Color.GetSaturation() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

32 Examples 7

1. Example

Project: DotSpatial
Source File: TwoColorSlider.cs
public void SetSaturation(Color startColor, Color endColor)
        {
            float sStart = startColor.GetSaturation();
            float sEnd = endColor.GetSaturation();
            _inverted = sEnd < sStart;
            LeftValue = sStart;
            RightValue = sEnd;
        }

2. Example

Project: semantic-colors
Source File: ColorAssigner.cs
private bool isBlackWhite(Color[,] image, CIELAB[,] imageLAB)
        {
            double nonGray = 0;
            double thresh = 0.001;
            CIELAB white = new CIELAB(100, 0, 0);
            CIELAB black = new CIELAB(0,0,0);

            int width = image.GetLength(0);
            int height = image.GetLength(1);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    Color color = image[i, j];
                    CIELAB lab = imageLAB[i, j];//Util.RGBtoLAB(color);
                    bool gray = color.GetSaturation() <= 0.2 || lab.SqDist(white) <= 5 || lab.SqDist(black) <= 5;

                    if (!gray)
                        nonGray++;
                }
            }
            return nonGray/(width*height) < thresh;
        }

3. Example

Project: GRBL-Plotter
Source File: svgPalette.cs
private static float ColorNum(Color c)
        { return c.GetSaturation() * 5 + getBrightness(c) * 4; }

4. Example

Project: naps2
Source File: ColorHelper.cs
public static void ColorToHSL(Color color, out double hue, out double saturation, out double brightness)
        {
            hue = color.GetHue();
            saturation = color.GetSaturation();
            brightness = color.GetBrightness();
        }

5. Example

Project: DotSpatial
Source File: DashSlider.cs
protected static LinearGradientBrush CreateGradientBrush(Color color, PointF topLeft, PointF bottomRight)
        {
            float b = color.GetBrightness();
            b += .3F;
            if (b > 1F) b = 1F;
            Color light = SymbologyGlobal.ColorFromHsl(color.GetHue(), color.GetSaturation(), b);
            float d = color.GetBrightness();
            d -= .3F;
            if (d < 0F) d = 0F;
            Color dark = SymbologyGlobal.ColorFromHsl(color.GetHue(), color.GetSaturation(), d);
            return new LinearGradientBrush(topLeft, bottomRight, light, dark);
        }

6. Example

Project: DotSpatial
Source File: SquareButton.cs
protected static LinearGradientBrush CreateGradientBrush(Color color, PointF topLeft, PointF bottomRight)
        {
            float b = color.GetBrightness();
            b += .3F;
            if (b > 1F) b = 1F;
            Color light = SymbologyGlobal.ColorFromHsl(color.GetHue(), color.GetSaturation(), b);
            float d = color.GetBrightness();
            d -= .3F;
            if (d < 0F) d = 0F;
            Color dark = SymbologyGlobal.ColorFromHsl(color.GetHue(), color.GetSaturation(), d);
            return new LinearGradientBrush(topLeft, bottomRight, light, dark);
        }

7. Example

Project: DotSpatial
Source File: TabColorControl.cs
private void SetEndHsl()
        {
            _endHue = (int)_endColor.GetHue();
            _endSat = _endColor.GetSaturation();
            _endLight = _endColor.GetBrightness();
        }

8. Example

Project: DotSpatial
Source File: TabColorControl.cs
private void SetStartHsl()
        {
            _startHue = (int)_startColor.GetHue();
            _startSat = _startColor.GetSaturation();
            _startLight = _startColor.GetBrightness();
        }

9. Example

Project: Alferd-Spritesheet-Unpacker
Source File: RGBHSLConverter.cs
public static HSL RGB_to_HSL(Color c)
        {
            HSL hsl = new HSL();

            hsl.H = c.GetHue() / 360.0; // we store hue as 0-1 as opposed to 0-360
            hsl.L = c.GetBrightness();
            hsl.S = c.GetSaturation();

            return hsl;
        }

10. Example

Project: scada
Source File: FrmSelectColor.cs
int IComparer.Compare(Object x, Object y)
            {
                Color cx = (Color)x;
                Color cy = (Color)y;
                float hx = cx.GetHue();
                float hy = cy.GetHue();
                float sx = cx.GetSaturation();
                float sy = cy.GetSaturation();
                float bx = cx.GetBrightness();
                float by = cy.GetBrightness();

                if (hx < hy) return -1;
                else if (hx > hy) return 1;
                else
                {
                    if (sx < sy) return -1;
                    else if (sx > sy) return 1;
                    else
                    {
                        if (bx < by) return -1;
                        else if (bx > by) return 1;
                        else return 0;
                    }
                }
            }

11. Example

Project: scada
Source File: ColorEditor.cs
int IComparer<object>.Compare(object x, object y)
            {
                Color cx = (Color)x;
                Color cy = (Color)y;
                float hx = cx.GetHue();
                float hy = cy.GetHue();
                float sx = cx.GetSaturation();
                float sy = cy.GetSaturation();
                float bx = cx.GetBrightness();
                float by = cy.GetBrightness();

                if (hx < hy) return -1;
                else if (hx > hy) return 1;
                else
                {
                    if (sx < sy) return -1;
                    else if (sx > sy) return 1;
                    else
                    {
                        if (bx < by) return -1;
                        else if (bx > by) return 1;
                        else return 0;
                    }
                }
            }

12. Example

Project: Sardauscan
Source File: ColorExtension.cs
internal static ColorHSB FromRGB(Color c)
		{
			ColorHSB hsb = new ColorHSB();

			hsb.Hue = c.GetHue() / 360.0; // we store hue as 0-1 as opposed to 0-360 
			hsb.Brightness = c.GetBrightness();
			hsb.Saturation = c.GetSaturation();

			return hsb;
		}

13. Example

Project: Cyotek.Windows.Forms.ColorPicker
Source File: AdobePhotoShopColorSwatchSerializer.cs
protected virtual void WritePalette(Stream stream, ColorCollection palette, AdobePhotoshopColorSwatc/n ..... /n //View Source file for more details /n }

14. Example

Project: DotSpatial
Source File: ColorExt.cs
public static Color Lighter(this Color self, float brightness)
        {
            float b = brightness + self.GetBrightness();
            if (b < 0F) b = 0F;
            if (b > 1F) b = 1F;
            return Color.FromArgb(self.A, SymbologyGlobal.ColorFromHsl(self.GetHue(), self.GetSaturation(), b));
        }

15. Example

Project: DotSpatial
Source File: ColorExt.cs
public static Color Darker(this Color self, float brightness)
        {
            float b = self.GetBrightness() - brightness;
            if (b < 0F) b = 0F;
            if (b > 1F) b = 1F;
            return Color.FromArgb(self.A, SymbologyGlobal.ColorFromHsl(self.GetHue(), self.GetSaturation(), b));
        }

16. Example

Project: DotSpatial
Source File: SymbologyGlobal.cs
public static Brush HighlightBrush(Rectangle box, Color selectionHighlight)
        {
            float med = selectionHighlight.GetBrightness();
            float bright = med + 0.05f;
            if (bright > 1f) bright = 1f;
            float dark = med - 0.05f;
            if (dark < 0f) dark = 0f;
            Color brtCol = ColorFromHsl(selectionHighlight.GetHue(), selectionHighlight.GetSaturation(), bright);
            Color drkCol = ColorFromHsl(selectionHighlight.GetHue(), selectionHighlight.GetSaturation(), dark);
            return new LinearGradientBrush(box, brtCol, drkCol, LinearGradientMode.Vertical);
        }

17. Example

Project: route-planner-csharp
Source File: LockedColorConverter.cs
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SolidColorBrush result = new SolidColorBrush();

            if (value != null)
            {
                try
                {
                    Color inputColor = ((SolidColorBrush)value).Color;
                    System.Drawing.Color color = System.Drawing.Color.FromArgb(inputColor.A,
                                                                               inputColor.R,
                                                                               inputColor.G,
                                                                               inputColor.B);

                    Color lockedColor = ConvertHSVtoRGB(color.GetHue(), color.GetSaturation(), LOCKED_BRIGHTNESS_VALUE);
                    result.Color = lockedColor;
                }
                catch
                {
                    result.Color = Colors.Transparent;
                }
            }
            else
                result.Color = Colors.Transparent;

            return result;
        }

18. Example

Project: kwyjibo
Source File: ImageFilters.cs
public static HSBColor SampleHSBAverage(Bitmap bmp, int x, int y)
        {
            var samples = new Color[5];

            // sample 5 pixels around x, y
            samples[0] = bmp.GetPixel(x, y);
            samples[1] = bmp.GetPixel(x - 2, y);
            samples[2] = bmp.GetPixel(x, y - 2);
            samples[3] = bmp.GetPixel(x + 2, y);
            samples[4] = bmp.GetPixel(x, y + 2);

            // take the average HSB
            var hue = samples[0].GetHue() + samples[1].GetHue() + samples[2].GetHue() + samples[3].GetHue() + samples[4].GetHue();
            var sat = samples[0].GetSaturation() + samples[1].GetSaturation() + samples[2].GetSaturation() + samples[3].GetSaturation() + samples[4].GetSaturation();
            var bri = samples[0].GetBrightness() + samples[1].GetBrightness() + samples[2].GetBrightness() + samples[3].GetBrightness() + samples[4].GetBrightness();

            return new HSBColor
            {
                Hue = (decimal)hue / 5m,
                Saturation = (decimal)sat / 5m,
                Brightness = (decimal)bri / 5m
            };
        }

19. Example

Project: route-planner-csharp
Source File: MapSymbolLockedColorConverter.cs
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        /n ..... /n //View Source file for more details /n }

20. Example

Project: route-planner-csharp
Source File: CustomSortComparers.cs
public int Compare(object x, object y)
        {
            Debug.Assert(x is Color);
            Debug.Assert(y is Color);

            float xBrightness = ((Color)x).GetBrightness();
            float yBrightness = ((Color)y).GetBrightness();

            int result = _CompareValues(xBrightness, yBrightness);

            // if brightness values are equals
            if (result == 0)
            {
                float xHue = ((Color)x).GetHue();
                float yHue = ((Color)y).GetHue();

                result = _CompareValues(xHue, yHue);

                // if hue values are equals
                if (result == 0)
                {
                    float xSaturation = ((Color)x).GetSaturation();
                    float ySaturation = ((Color)y).GetSaturation();

                    return _CompareValues(xSaturation, ySaturation);
                }
                else
                    return result;
            }
            else
                return result;
        }

21. Example

Project: AudioSwitch
Source File: DeviceIcons.cs
internal static Bitmap ChangeColors(Bitmap bmp, int hue, float saturation, float brightness)
        {
            for (var y = 0; y < bmp.Height; y++)
                for (var x = 0; x < bmp.Width; x++)
                {
                    var p = bmp.GetPixel(x, y);
                    var pb = p.GetBrightness() + brightness;
                    pb = pb < 0 ? 0 : pb;
                    pb = pb > 1 ? 1 : pb;

                    var c = ColorFromAhsb(p.A, hue, p.GetSaturation() + saturation, pb);
                    bmp.SetPixel(x, y, c);
                }
            return bmp;
        }

22. Example

Project: ATF
Source File: D2dDefaultTimelineRenderer.cs
protected override void Draw(IInterval interval, RectangleF bounds, DrawMode drawMode, Context c)
  /n ..... /n //View Source file for more details /n }

23. Example

Project: ATF
Source File: DefaultTimelineRenderer.cs
protected override void Draw(IInterval interval, RectangleF bounds, DrawMode drawMode, Context c)
  /n ..... /n //View Source file for more details /n }

24. Example

Project: DotSpatial
Source File: PolarControl.cs
protected override void OnBackColorChanged(EventArgs e)
        {
            base.OnBackColorChange/n ..... /n //View Source file for more details /n }

25. Example

Project: DotSpatial
Source File: PolarControl.cs
private void DoBackColorChanged(EventArgs e)
        {
            base.OnBackColorChanged(e);

    /n ..... /n //View Source file for more details /n }

26. Example

Project: ATF
Source File: OverlayButton.cs
private Bitmap CreateNewBitmap(Bitmap src, float saturation, float brightness)
        {
            Bitmap result = (Bitmap)src.Clone();
            for (int y = 0; y < src.Height; y++)
            {
                for (int x = 0; x < src.Width; x++)
                {
                    Color srcColor = src.GetPixel(x, y);
                    float s = MathUtil.Clamp(srcColor.GetSaturation() + saturation, 0.0f, 1.0f);
                    float b = MathUtil.Clamp(srcColor.GetBrightness() + brightness, 0.0f, 1.0f);

                    Color destColor = ColorUtil.FromAhsb(srcColor.A, srcColor.GetHue(), s, b);
                    result.SetPixel(x, y, destColor);
                }
            }
            return result;
        }

27. Example

Project: MaxLifx
Source File: ScreenColourProcessor.cs
private void DoMainLoop(MaxLifxBulbController bulbController, ref int frames, DateTime start,
      /n ..... /n //View Source file for more details /n }

28. Example

Project: MapViewer
Source File: Effect.cs
protected Color CalculateIntermediary(Color from, Color to, float fractionDone) {
            if (fractionDone >= 1.0f)
                return to;

            if (fractionDone <= 0.0f)
                return from;

            // There are a couple of different strategies we could use here:
            // - Calc intermediary individual RGB components - fastest
            // - Calc intermediary HSB components - nicest results, but slower

            //Color c = Color.FromArgb(
            //    this.CalculateIntermediary(from.R, to.R, fractionDone),
            //    this.CalculateIntermediary(from.G, to.G, fractionDone),
            //    this.CalculateIntermediary(from.B, to.B, fractionDone)
            //);
            Color c = FromHSB(
                this.CalculateIntermediary(from.GetHue(), to.GetHue(), fractionDone),
                this.CalculateIntermediary(from.GetSaturation(), to.GetSaturation(), fractionDone),
                this.CalculateIntermediary(from.GetBrightness(), to.GetBrightness(), fractionDone)
            );

            return Color.FromArgb(this.CalculateIntermediary(from.A, to.A, fractionDone), c);
        }

29. Example

Project: kwyjibo
Source File: ImageFilters.cs
public static unsafe void HSLFilter(Bitmap bmp, float h, float s, float l, float ht, float st, float lt)
        {
            BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            byte* bmpPtrA = (byte*)(data.Scan0);
            int move = data.Stride - data.Width * 3;

            float hd, sd, ld;
            Color c;

            for (int i = 0; i < data.Height; i++)
            {
                for (int j = 0; j < data.Width; j++)
                {
                    c = Color.FromArgb(bmpPtrA[2], bmpPtrA[1], bmpPtrA[0]);
                    hd = Math.Abs(((((c.GetHue() - h) % 360) + 540) % 360) - 180);
                    sd = Math.Abs(c.GetSaturation() - s);
                    ld = Math.Abs(c.GetBrightness() - l);

                    if (hd < 0 || hd > ht || sd > st || ld > lt)
                    {
                        bmpPtrA[0] = 0;
                        bmpPtrA[1] = 0;
                        bmpPtrA[2] = 0;
                    }

                    bmpPtrA += 3;
                }
                bmpPtrA += move;
            }

            bmp.UnlockBits(data);
        }

30. Example

Project: Chromatics
Source File: HueInterface.cs
public async void HueUpdateStateBrightness(BulbModeTypes mode, Color col, int? brightness, int trans/n ..... /n //View Source file for more details /n }

31. Example

Project: Chromatics
Source File: LIFXInterface.cs
public async void LifxUpdateStateBrightness(BulbModeTypes mode, Color col, ushort brightness, int tr/n ..... /n //View Source file for more details /n }

32. Example

Project: DotSpatial
Source File: ModelElement.cs
public virtual void Paint(Graphics graph)
        {
            // Sets up the colors to use
       /n ..... /n //View Source file for more details /n }