示例#1
0
        // Y = Brightness 100 -> 0
        protected override void DrawBrightness()
        {
            using (var graphics = Graphics.FromImage(bmp))
            {
                var start = new Hsb(SelectedColor.Hsb.Hue, SelectedColor.Hsb.Saturation, 1.0, SelectedColor.Rgba.Alpha);
                var end   = new Hsb(SelectedColor.Hsb.Hue, SelectedColor.Hsb.Saturation, 0.0, SelectedColor.Rgba.Alpha);

                using (var brush = new LinearGradientBrush(new Rectangle(0, 0, clientWidth, clientHeight), start, end, LinearGradientMode.Vertical))
                {
                    graphics.FillRectangle(brush, new Rectangle(0, 0, clientWidth, clientHeight));
                }
            }
        }
示例#2
0
        protected override void DrawHue()
        {
            using (var graphics = Graphics.FromImage(bmp))
            {
                var color = new Hsb(0.0, 1.0, 1.0, SelectedColor.Rgba.Alpha);

                for (var y = 0; y < clientHeight; y++)
                {
                    color.Hue = 1.0 - ((double)y / (clientHeight - 1));

                    using (var pen = new Pen(color))
                    {
                        graphics.DrawLine(pen, 0, y, clientWidth, y);
                    }
                }
            }
        }
示例#3
0
        public static Color HsbToColor(Hsb hsb)
        {
            int mid;
            var max = (int)Math.Round(hsb.Brightness * 255);
            var min = (int)Math.Round((1.0 - hsb.Saturation) * (hsb.Brightness / 1.0) * 255);
            var q   = (double)(max - min) / 255;

            if (hsb.Hue >= 0 && hsb.Hue <= (double)1 / 6)
            {
                mid = (int)Math.Round((hsb.Hue - 0) * q * 1530 + min);
                return(Color.FromArgb(hsb.Alpha, max, mid, min));
            }

            if (hsb.Hue <= (double)1 / 3)
            {
                return(Color.FromArgb(hsb.Alpha, (int)Math.Round(-((hsb.Hue - (double)1 / 6) * q) * 1530 + max), max,
                                      min));
            }

            if (hsb.Hue <= 0.5)
            {
                mid = (int)Math.Round((hsb.Hue - (double)1 / 3) * q * 1530 + min);
                return(Color.FromArgb(hsb.Alpha, min, max, mid));
            }

            if (hsb.Hue <= (double)2 / 3)
            {
                mid = (int)Math.Round(-((hsb.Hue - 0.5) * q) * 1530 + max);
                return(Color.FromArgb(hsb.Alpha, min, mid, max));
            }

            if (hsb.Hue <= (double)5 / 6)
            {
                mid = (int)Math.Round((hsb.Hue - (double)2 / 3) * q * 1530 + min);
                return(Color.FromArgb(hsb.Alpha, mid, min, max));
            }

            if (hsb.Hue <= 1.0)
            {
                mid = (int)Math.Round(-((hsb.Hue - (double)5 / 6) * q) * 1530 + max);
                return(Color.FromArgb(hsb.Alpha, max, min, mid));
            }

            return(Color.FromArgb(hsb.Alpha, 0, 0, 0));
        }
示例#4
0
        /// <summary>
        /// </summary>
        protected override void DrawBrightness()
        {
            using (var g = Graphics.FromImage(bmp))
            {
                var start = new Hsb(0.0, 1.0, SelectedColor.Hsb.Brightness, SelectedColor.Rgba.Alpha);
                var end   = new Hsb(0.0, 0.0, SelectedColor.Hsb.Brightness, SelectedColor.Rgba.Alpha);

                for (var x = 0; x < clientWidth; x++)
                {
                    start.Hue = end.Hue = (double)x / (clientHeight - 1);

                    using (var brush = new LinearGradientBrush(new Rectangle(0, 0, 1, clientHeight), start, end, LinearGradientMode.Vertical))
                    {
                        g.FillRectangle(brush, new Rectangle(x, 0, 1, clientHeight));
                    }
                }
            }
        }
示例#5
0
        /// <summary>
        /// </summary>
        protected override void DrawHue()
        {
            using (var graphics = Graphics.FromImage(bmp))
            {
                var start = new Hsb(SelectedColor.Hsb.Hue, 0.0, 0.0, SelectedColor.Rgba.Alpha);
                var end   = new Hsb(SelectedColor.Hsb.Hue, 1.0, 0.0, SelectedColor.Rgba.Alpha);

                for (var y = 0; y < clientHeight; y++)
                {
                    start.Brightness = end.Brightness = 1.0 - (double)y / (clientHeight - 1);

                    using (var brush = new LinearGradientBrush(new Rectangle(0, 0, clientWidth, 1), start, end, LinearGradientMode.Horizontal))
                    {
                        graphics.FillRectangle(brush, new Rectangle(0, y, clientWidth, 1));
                    }
                }
            }
        }
示例#6
0
 /// <summary>
 /// </summary>
 public void RgbaUpdate()
 {
     Hsb  = Rgba;
     Cmyk = Rgba;
 }
示例#7
0
 /// <summary>
 /// </summary>
 /// <param name="color"></param>
 public MyColor(Color color)
 {
     Rgba = color;
     Hsb  = color;
     Cmyk = color;
 }
示例#8
0
 /// <summary>
 /// </summary>
 public void CmykUpdate()
 {
     Rgba = Cmyk;
     Hsb  = Cmyk;
 }
示例#9
0
 public bool Equals(Hsb other)
 {
     return(_hue.Equals(other._hue) && _saturation.Equals(other._saturation) && _brightness.Equals(other._brightness) && _alpha == other._alpha);
 }
示例#10
0
        public static Hsb ColorToHsb(Color color)
        {
            var 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;
            }

            var 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;
            }

            hsb.Alpha = color.A;

            return(hsb);
        }