HSV (HSB) カラーを表す
Exemplo n.º 1
0
 internal void OnSelectColorChanged(HsvColor color)
 {
     if (SelectColorChanged != null)
     {
         SelectColorChanged(color);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 指定したHsvColorからColorを作成する
        /// </summary>
        /// <param name="hsv">HsvColor</param>
        /// <returns>Color</returns>
        public static Color ToRgb(HsvColor hsv)
        {
            float v = hsv.V;
                float s = hsv.S;

                float r, g, b;
                if (s == 0)
                {
                    r = v;
                    g = v;
                    b = v;
                }
                else
                {
                    float h = hsv.H / 60f;
                    int i = (int)Math.Floor(h);
                    float f = h - i;
                    float p = v * (1f - s);
                    float q;
                    if (i % 2 == 0)
                    {
                        //t
                        q = v * (1f - (1f - f) * s);
                    }
                    else
                    {
                        q = v * (1f - f * s);
                    }

                    switch (i)
                    {
                        case 0:
                            r = v;
                            g = q;
                            b = p;
                            break;
                        case 1:
                            r = q;
                            g = v;
                            b = p;
                            break;
                        case 2:
                            r = p;
                            g = v;
                            b = q;
                            break;
                        case 3:
                            r = p;
                            g = q;
                            b = v;
                            break;
                        case 4:
                            r = q;
                            g = p;
                            b = v;
                            break;
                        case 5:
                            r = v;
                            g = p;
                            b = q;
                            break;
                        default:
                            throw new ArgumentException(
                                "色相の値が不正です。", "hsv");
                    }
                }

                return Color.FromArgb(
                    (byte)255,
                    (byte)Math.Round(r * 255f),
                    (byte)Math.Round(g * 255f),
                    (byte)Math.Round(b * 255f));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 指定したHsvColorからColorを作成する
        /// </summary>
        /// <param name="hsv">HsvColor</param>
        /// <returns>Color</returns>
        public static Color ToRgb(HsvColor hsv)
        {
            float v = hsv.V;
            float s = hsv.S;

            float r, g, b;

            if (s == 0)
            {
                r = v;
                g = v;
                b = v;
            }
            else
            {
                float h = hsv.H / 60f;
                int   i = (int)Math.Floor(h);
                float f = h - i;
                float p = v * (1f - s);
                float q;
                if (i % 2 == 0)
                {
                    //t
                    q = v * (1f - (1f - f) * s);
                }
                else
                {
                    q = v * (1f - f * s);
                }

                switch (i)
                {
                case 0:
                    r = v;
                    g = q;
                    b = p;
                    break;

                case 1:
                    r = q;
                    g = v;
                    b = p;
                    break;

                case 2:
                    r = p;
                    g = v;
                    b = q;
                    break;

                case 3:
                    r = p;
                    g = q;
                    b = v;
                    break;

                case 4:
                    r = q;
                    g = p;
                    b = v;
                    break;

                case 5:
                    r = v;
                    g = p;
                    b = q;
                    break;

                default:
                    throw new ArgumentException(
                              "色相の値が不正です。", "hsv");
                }
            }

            return(Color.FromArgb(
                       (byte)255,
                       (byte)Math.Round(r * 255f),
                       (byte)Math.Round(g * 255f),
                       (byte)Math.Round(b * 255f)));
        }