Exemplo n.º 1
0
        public HsbaColor(string hexColor)
        {
            HsbaColor hsba = Utility.RgbaToHsba(new RgbaColor(hexColor));

            H = hsba.H;
            S = hsba.S;
            B = hsba.B;
            A = hsba.A;
        }
Exemplo n.º 2
0
        public HsbaColor(int r, int g, int b, int a = 255)
        {
            HsbaColor hsba = Utility.RgbaToHsba(new RgbaColor(r, g, b, a));

            H = hsba.H;
            S = hsba.S;
            B = hsba.B;
            A = hsba.A;
        }
Exemplo n.º 3
0
        public HsbaColor(Brush brush)
        {
            HsbaColor hsba = Utility.RgbaToHsba(new RgbaColor(brush));

            H = hsba.H;
            S = hsba.S;
            B = hsba.B;
            A = hsba.A;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Hsba转Rgba
        /// </summary>
        /// <param name="hsba"></param>
        /// <returns></returns>
        internal static RgbaColor HsbaToRgba(HsbaColor hsba)
        {
            double r = 0, g = 0, b = 0;
            int    i = (int)((hsba.H / 60) % 6);
            double f = (hsba.H / 60) - i;
            double p = hsba.B * (1 - hsba.S);
            double q = hsba.B * (1 - f * hsba.S);
            double t = hsba.B * (1 - (1 - f) * hsba.S);

            switch (i)
            {
            case 0:
                r = hsba.B;
                g = t;
                b = p;
                break;

            case 1:
                r = q;
                g = hsba.B;
                b = p;
                break;

            case 2:
                r = p;
                g = hsba.B;
                b = t;
                break;

            case 3:
                r = p;
                g = q;
                b = hsba.B;
                break;

            case 4:
                r = t;
                g = p;
                b = hsba.B;
                break;

            case 5:
                r = hsba.B;
                g = p;
                b = q;
                break;

            default:
                break;
            }
            return(new RgbaColor((int)(255.0 * r), (int)(255.0 * g), (int)(255.0 * b), (int)(255.0 * hsba.A)));
        }