Ejemplo n.º 1
0
        public RgbaColor(double h, double s, double b, double a = 1)
        {
            RgbaColor rgba = Utility.HsbaToRgba(new HsbaColor(h, s, b, a));

            R = rgba.R;
            G = rgba.G;
            B = rgba.B;
            A = rgba.A;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Rgba转Hsba
        /// </summary>
        /// <param name="rgba"></param>
        /// <returns></returns>
        internal static HsbaColor RgbaToHsba(RgbaColor rgba)
        {
            int[] rgb = new int[] { rgba.R, rgba.G, rgba.B };
            Array.Sort(rgb);
            int max = rgb[2];
            int min = rgb[0];

            double hsbB = max / 255.0;
            double hsbS = max == 0 ? 0 : (max - min) / (double)max;
            double hsbH = 0;

            if (rgba.R == rgba.G && rgba.R == rgba.B)
            {
            }
            else
            {
                if (max == rgba.R && rgba.G >= rgba.B)
                {
                    hsbH = (rgba.G - rgba.B) * 60.0 / (max - min) + 0.0;
                }
                else if (max == rgba.R && rgba.G < rgba.B)
                {
                    hsbH = (rgba.G - rgba.B) * 60.0 / (max - min) + 360.0;
                }
                else if (max == rgba.G)
                {
                    hsbH = (rgba.B - rgba.R) * 60.0 / (max - min) + 120.0;
                }
                else if (max == rgba.B)
                {
                    hsbH = (rgba.R - rgba.G) * 60.0 / (max - min) + 240.0;
                }
            }

            return(new HsbaColor(hsbH, hsbS, hsbB, rgba.A / 255.0));
        }