コード例 #1
0
        public static Color ToColor(HSB hsb)
        {
            int Mid;

            int    Max = ColorHelper.Round(hsb.Brightness * 255);
            int    Min = ColorHelper.Round((1.0 - hsb.Saturation) * (hsb.Brightness / 1.0) * 255);
            double q   = (double)(Max - Min) / 255;

            if (hsb.Hue >= 0 && hsb.Hue <= (double)1 / 6)
            {
                Mid = ColorHelper.Round(((hsb.Hue - 0) * q) * 1530 + Min);
                return(Color.FromArgb(Max, Mid, Min));
            }
            if (hsb.Hue <= (double)1 / 3)
            {
                Mid = ColorHelper.Round(-((hsb.Hue - (double)1 / 6) * q) * 1530 + Max);
                return(Color.FromArgb(Mid, Max, Min));
            }
            if (hsb.Hue <= 0.5)
            {
                Mid = ColorHelper.Round(((hsb.Hue - (double)1 / 3) * q) * 1530 + Min);
                return(Color.FromArgb(Min, Max, Mid));
            }
            if (hsb.Hue <= (double)2 / 3)
            {
                Mid = ColorHelper.Round(-((hsb.Hue - 0.5) * q) * 1530 + Max);
                return(Color.FromArgb(Min, Mid, Max));
            }
            if (hsb.Hue <= (double)5 / 6)
            {
                Mid = ColorHelper.Round(((hsb.Hue - (double)2 / 3) * q) * 1530 + Min);
                return(Color.FromArgb(Mid, Min, Max));
            }
            if (hsb.Hue <= 1.0)
            {
                Mid = ColorHelper.Round(-((hsb.Hue - (double)5 / 6) * q) * 1530 + Max);
                return(Color.FromArgb(Max, Min, Mid));
            }
            return(Color.FromArgb(0, 0, 0));
        }
コード例 #2
0
 public void CMYKUpdate()
 {
     this.RGB = this.CMYK;
     this.HSB = this.CMYK;
 }
コード例 #3
0
 public void RGBUpdate()
 {
     this.HSB  = this.RGB;
     this.CMYK = this.RGB;
 }
コード例 #4
0
        public static HSB ToHSB(Color color)
        {
            HSB hsb = new HSB();

            int Max, Min;

            if (color.R > color.G)
            {
                Max = color.R; Min = color.G;
            }
            else
            {
                Max = color.G; Min = color.R;
            }
            if (color.B > Max)
            {
                Max = color.B;
            }
            else if (color.B < Min)
            {
                Min = color.B;
            }

            int Diff = Max - Min;

            hsb.Brightness = (double)Max / 255;

            if (Max == 0)
            {
                hsb.Saturation = 0;
            }
            else
            {
                hsb.Saturation = (double)Diff / Max;
            }

            double q;

            if (Diff == 0)
            {
                q = 0;
            }
            else
            {
                q = (double)60 / Diff;
            }

            if (Max == color.R)
            {
                if (color.G < color.B)
                {
                    hsb.Hue = (360 + q * (color.G - color.B)) / 360;
                }
                else
                {
                    hsb.Hue = q * (color.G - color.B) / 360;
                }
            }
            else if (Max == color.G)
            {
                hsb.Hue = (120 + q * (color.B - color.R)) / 360;
            }
            else if (Max == color.B)
            {
                hsb.Hue = (240 + q * (color.R - color.G)) / 360;
            }
            else
            {
                hsb.Hue = 0.0;
            }

            return(hsb);
        }
コード例 #5
0
 public MyColor(Color color)
 {
     this.RGB  = color;
     this.HSB  = color;
     this.CMYK = color;
 }