ColorToHsv() public static method

public static ColorToHsv ( Color color, double &h, double &s, double &v ) : void
color Color
h double
s double
v double
return void
        //---------------------------------------------------------------------------------------------
        // R、G、B 用アップダウンコントロールを操作したとき
        private void PART_RgbUpDown_ValueChanged(Object sender, RoutedPropertyChangedEventArgs <int> args)
        {
            NumericUpDown control = sender as NumericUpDown;

            if (control == null)
            {
                return;
            }

            bool  isHandled = false;
            byte  newValue  = (byte)args.NewValue;
            Color color     = this.SelectedColor;

            switch (control.Name)
            {
            case "PART_RedUpDown":
                if (color.R != newValue)
                {
                    color.R   = newValue;
                    this.Red  = newValue;
                    isHandled = true;
                }
                break;

            case "PART_GreenUpDown":
                if (color.G != newValue)
                {
                    color.G    = newValue;
                    this.Green = newValue;
                    isHandled  = true;
                }
                break;

            case "PART_BlueUpDown":
                if (color.B != newValue)
                {
                    color.B   = newValue;
                    this.Blue = newValue;
                    isHandled = true;
                }
                break;
            }

            if (isHandled)
            {
                this.SelectedColor = color;
                FOldSelectedColor  = this.SelectedColor;

                Color c = Color.FromRgb(this.SelectedColor.R, this.SelectedColor.G, this.SelectedColor.B);

                double h, s, v;
                ColorUtility.ColorToHsv(c, out h, out s, out v);

                this.Hue        = System.Convert.ToInt32(h);
                this.Saturation = System.Convert.ToSingle(s);
                this.Brightness = System.Convert.ToSingle(v);
            }
        }
        //---------------------------------------------------------------------------------------------
        private void userControl_Loaded(object sender, RoutedEventArgs e)
        {
            PART_HueGrid.HueChanged += new RoutedPropertyChangedEventHandler <int>(PART_HueGrid_HueChanged);

            Color c = Color.FromRgb(this.SelectedColor.R, this.SelectedColor.G, this.SelectedColor.B);

            double h, s, v;

            ColorUtility.ColorToHsv(c, out h, out s, out v);
            this.Hue = (int)h;

            // 色調(Hue)選択用カラーバーを設定する
            this.SetHueColorBar();

            // コントロールを初期化する
            this.SetSVList(this.Hue);
            this.SetUpColorCanvas(this.Hue);

            // アルファ値用スライダーコントロール
            PART_AlphaSlider.Value = this.SelectedColor.A;

            // アップダウンコントロールの Value プロパティを設定する
            this.SetUpdownWithSelectedColor(this.SelectedColor, 0);

            // SelectedColor プロパティを外部から変更したとき(たとえば、初期値として与えられたとき)
            if (FOldSelectedColor != this.SelectedColor)
            {
                int index = 0;

                foreach (object item in PART_UniformGrid.Children)
                {
                    Rectangle rect      = (Rectangle)item;
                    CellColor cellColor = SVList[index];

                    if (((s >= cellColor.S1) && (s < cellColor.S2)) && ((v <= cellColor.V1) && (v > cellColor.V2)))
                    {
                        var args = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
                        this.rect_MouseLeftButtonDown(rect, args);

                        break;
                    }

                    ++index;
                }
            }

            PART_HueGrid.Hue  = this.Hue;
            FOldSelectedColor = this.SelectedColor;
        }
        //---------------------------------------------------------------------------------------------
        // 指定の SelectedColor 型に基づいて、各アップダウンコントロールの Value プロパティを設定する
        // このメソッドは、userControl_Loaded、PART_Hexadecimal_KeyDown、rect_MouseLeftButtonDown イベント内で呼ばれる
        // n はどこから呼ばれたかをチェックするための番号で、デバッグ目的にしか使わない
        private void SetUpdownWithSelectedColor(Color color, int n)
        {
//			Debug.Print(String.Format("SetUpdownWithSelectedColor: {0} {1}", n, color));

            this.Alpha = color.A;
            this.Red   = color.R;
            this.Green = color.G;
            this.Blue  = color.B;

            Color c = Color.FromRgb(color.R, color.G, color.B);

            double h, s, v;

            ColorUtility.ColorToHsv(c, out h, out s, out v);

            this.Hue        = System.Convert.ToInt32(h);
            this.Saturation = System.Convert.ToSingle(s);
            this.Brightness = System.Convert.ToSingle(v);
        }
        //---------------------------------------------------------------------------------------------
        private void PART_Hexadecimal_KeyDown(object sender, KeyEventArgs e)
        {
            // 入力後、[Return] を押したとき
            if (e.Key == Key.Return)
            {
                this.SelectedColor = ColorUtility.ConvertColorFromString(PART_Hexadecimal.Text);
                FOldSelectedColor  = this.SelectedColor;

                // アップダウンコントロールの Value プロパティを設定する
                this.SetUpdownWithSelectedColor(this.SelectedColor, 1);

                Color c = Color.FromRgb(this.SelectedColor.R, this.SelectedColor.G, this.SelectedColor.B);

                // アルファ値用スライダーコントロール
                PART_AlphaSlider.Value = this.SelectedColor.A;

                double h, s, v;
                ColorUtility.ColorToHsv(c, out h, out s, out v);

                // Hue 値に基づいてカラーキャンバスを設定する
                PART_HueGrid.Hue = (int)h;
                this.SetColorCanvasWithHue((int)h);

                int index = 0;

                foreach (object item in PART_UniformGrid.Children)
                {
                    Rectangle rect      = (Rectangle)item;
                    CellColor cellColor = SVList[index];

                    if (((s >= cellColor.S1) && (s < cellColor.S2)) && ((v <= cellColor.V1) && (v > cellColor.V2)))
                    {
                        var args = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left);
                        this.rect_MouseLeftButtonDown(rect, args);

                        break;
                    }

                    ++index;
                }
            }
        }