Пример #1
0
        // Y = Hue 360 -> 0
        protected override void DrawHue()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB color = new HSB(0.0, 1.0, 1.0, SelectedColor.RGBA.Alpha);

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

                    using (Pen pen = new Pen(color))
                    {
                        g.DrawLine(pen, 0, y, width, y);
                    }
                }
            }
        }
Пример #2
0
        // Y = Saturation 100 -> 0
        protected override void DrawSaturation()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB color = new HSB(SelectedColor.HSB.Hue, 0.0, SelectedColor.HSB.Brightness, SelectedColor.RGBA.Alpha);

                for (int y = 0; y < ClientHeight; y++)
                {
                    color.Saturation = 1.0 - (double)y / (ClientHeight - 1);

                    using (Pen pen = new Pen(color))
                    {
                        g.DrawLine(pen, 0, y, ClientWidth, y);
                    }
                }
            }
        }
Пример #3
0
        // Y = Brightness 100 -> 0
        protected override void DrawBrightness()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB color = new HSB(SelectedColor.HSB.Hue, SelectedColor.HSB.Saturation, 0.0, SelectedColor.RGBA.Alpha);

                for (int y = 0; y < ClientHeight; y++)
                {
                    color.Brightness = 1.0 - (double)y / (ClientHeight - 1);

                    using (Pen pen = new Pen(color))
                    {
                        g.DrawLine(pen, 0, y, ClientWidth, y);
                    }
                }
            }
        }
Пример #4
0
        public static Color HSBToColor(HSB hsb)
        {
            int    Mid;
            int    Max = (int)Math.Round(hsb.Brightness * 255);
            int    Min = (int)Math.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 = (int)Math.Round(((hsb.Hue - 0) * q) * 1530 + Min);
                return(Color.FromArgb(hsb.Alpha, Max, Mid, Min));
            }

            if (hsb.Hue <= (double)1 / 3)
            {
                Mid = (int)Math.Round(-((hsb.Hue - (double)1 / 6) * q) * 1530 + Max);
                return(Color.FromArgb(hsb.Alpha, Mid, 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));
        }
Пример #5
0
        // X = Hue 0 -> 360
        // Y = Saturation 100 -> 0
        protected override void DrawBrightness()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB start = new HSB(0.0, 1.0, SelectedColor.HSB.Brightness, SelectedColor.RGBA.Alpha);
                HSB end   = new HSB(0.0, 0.0, SelectedColor.HSB.Brightness, SelectedColor.RGBA.Alpha);

                for (int x = 0; x < ClientWidth; x++)
                {
                    start.Hue = end.Hue = (double)x / (ClientHeight - 1);

                    using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, 1, ClientHeight), start, end, LinearGradientMode.Vertical))
                    {
                        g.FillRectangle(brush, new Rectangle(x, 0, 1, ClientHeight));
                    }
                }
            }
        }
Пример #6
0
        // X = Saturation 0 -> 100
        // Y = Brightness 100 -> 0
        protected override void DrawHue()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB start = new HSB(SelectedColor.HSB.Hue, 0.0, 0.0, SelectedColor.RGBA.Alpha);
                HSB end   = new HSB(SelectedColor.HSB.Hue, 1.0, 0.0, SelectedColor.RGBA.Alpha);

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

                    using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, ClientWidth, 1), start, end, LinearGradientMode.Horizontal))
                    {
                        g.FillRectangle(brush, new Rectangle(0, y, ClientWidth, 1));
                    }
                }
            }
        }
Пример #7
0
        // X = Saturation 0 -> 100
        // Y = Brightness 100 -> 0
        protected override void DrawHue()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB start = new HSB(SelectedColor.HSB.Hue, 0.0, 0.0, SelectedColor.RGBA.Alpha);
                HSB end = new HSB(SelectedColor.HSB.Hue, 1.0, 0.0, SelectedColor.RGBA.Alpha);

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

                    using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, ClientWidth, 1), start, end, LinearGradientMode.Horizontal))
                    {
                        g.FillRectangle(brush, new Rectangle(0, y, ClientWidth, 1));
                    }
                }
            }
        }
Пример #8
0
        // X = Hue 0 -> 360
        // Y = Saturation 100 -> 0
        protected override void DrawBrightness()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB start = new HSB(0.0, 1.0, SelectedColor.HSB.Brightness, SelectedColor.RGBA.Alpha);
                HSB end = new HSB(0.0, 0.0, SelectedColor.HSB.Brightness, SelectedColor.RGBA.Alpha);

                for (int x = 0; x < ClientWidth; x++)
                {
                    start.Hue = end.Hue = (double)x / (ClientHeight - 1);

                    using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, 1, ClientHeight), start, end, LinearGradientMode.Vertical))
                    {
                        g.FillRectangle(brush, new Rectangle(x, 0, 1, ClientHeight));
                    }
                }
            }
        }
Пример #9
0
        public static HSB ColorToHSB(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;

            hsb.Alpha = color.A;

            return hsb;
        }
Пример #10
0
 public void CMYKUpdate()
 {
     RGBA = CMYK;
     HSB  = CMYK;
 }
Пример #11
0
        public static Color HSBToColor(HSB hsb)
        {
            int Mid;
            int Max = (int)Math.Round(hsb.Brightness * 255);
            int Min = (int)Math.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 = (int)Math.Round(((hsb.Hue - 0) * q) * 1530 + Min);
                return Color.FromArgb(hsb.Alpha, Max, Mid, Min);
            }

            if (hsb.Hue <= (double)1 / 3)
            {
                Mid = (int)Math.Round(-((hsb.Hue - (double)1 / 6) * q) * 1530 + Max);
                return Color.FromArgb(hsb.Alpha, Mid, 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);
        }
Пример #12
0
        public static HSB ColorToHSB(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;
            }

            hsb.Alpha = color.A;

            return(hsb);
        }
Пример #13
0
        // Y = Hue 360 -> 0
        protected override void DrawHue()
        {
            using (Graphics g = Graphics.FromImage(bmp))
            {
                HSB color = new HSB(0.0, 1.0, 1.0, SelectedColor.RGBA.Alpha);

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

                    using (Pen pen = new Pen(color))
                    {
                        g.DrawLine(pen, 0, y, width, y);
                    }
                }
            }
        }
Пример #14
0
 public void CMYKUpdate()
 {
     RGBA = CMYK;
     HSB = CMYK;
 }
Пример #15
0
 public void RGBAUpdate()
 {
     HSB = RGBA;
     CMYK = RGBA;
 }
Пример #16
0
 public MyColor(Color color)
 {
     RGBA = color;
     HSB = color;
     CMYK = color;
 }
Пример #17
0
 public void RGBAUpdate()
 {
     HSB  = RGBA;
     CMYK = RGBA;
 }
Пример #18
0
 public MyColor(Color color)
 {
     RGBA = color;
     HSB  = color;
     CMYK = color;
 }