Пример #1
0
        public ColorPicker()
        {
            InitializeComponent();

            var g6 = HSV.GradientSpectrum();

            LinearGradientBrush gradientBrush = new LinearGradientBrush();

            gradientBrush.StartPoint = new Point(0, 0);
            gradientBrush.EndPoint   = new Point(1, 0);
            for (int i = 0; i < g6.Length; i++)
            {
                GradientStop stop = new GradientStop(g6[i].Color(), (i) * 0.16);
                gradientBrush.GradientStops.Add(stop);
            }
            SpectrumGrid.Opacity    = 1;
            SpectrumGrid.Background = gradientBrush;

            MiddleStop.Color = HSV.RGBFromHSV(0, 1f, 1f).Color();
        }
Пример #2
0
 private void RgbGradient_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
 {
     if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
     {
         var pos = e.GetPosition(sender as Canvas);
         var x   = pos.X;
         var y   = pos.Y;
         RGB c;
         if (x < Width / 2)
         {
             c = HSV.RGBFromHSV(currH, 1f, x / (Width / 2));
         }
         else
         {
             c = HSV.RGBFromHSV(currH, (Width / 2 - (x - Width / 2)) / Width, 1f);
         }
         HexCode.Background = new SolidColorBrush(c.Color());
         HexCode.Text       = "#" + c.Hex();
         Selected           = c;
     }
 }