예제 #1
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rect = ClientRectangle;

            if (_needToRecrateInternalImage)
            {
                _saturationBrightnessImage  = new Bitmap(rect.Width, rect.Height, e.Graphics);
                _needToRecrateInternalImage = false;

                Graphics gr = Graphics.FromImage(_saturationBrightnessImage);

                Color color = ColorUtils.HsbToRgb(_hue, 100.0, 100.0);

                double r    = ((double)(255 - color.R)) / rect.Width;
                double g    = ((double)(255 - color.G)) / rect.Width;
                double b    = ((double)(255 - color.B)) / rect.Width;
                double num4 = 255;
                double num5 = 255;
                double num6 = 255;
                for (int num7 = rect.Left; num7 <= rect.Right; num7++)
                {
                    using (LinearGradientBrush brush1 = new LinearGradientBrush(new Rectangle(num7, rect.Top, 1, rect.Height + 1), Color.FromArgb((int)Math.Round(num4), (int)Math.Round(num5), (int)Math.Round(num6)), Color.FromArgb(0, 0, 0), 90f, false))
                    {
                        gr.FillRectangle(brush1, new Rectangle(num7, rect.Top, 1, rect.Height + 1));
                    }
                    num4 -= r;
                    num5 -= g;
                    num6 -= b;
                }

                gr.Dispose();
            }

            e.Graphics.DrawImage(_saturationBrightnessImage, 0, 0);

            // Draw the color tracker
            int       x          = (int)Math.Round(_saturation / 100.0 * rect.Width);
            int       y          = rect.Height - (int)Math.Round(_brightness / 100.0 * rect.Height);
            Rectangle circleRect = new Rectangle(x - 5, y - 5, 10, 10);
            Pen       pen        = new Pen(Color.White);

            e.Graphics.DrawEllipse(pen, circleRect);
            pen.Dispose();
            circleRect.Inflate(1, 1);
            pen = new Pen(Color.Black);
            e.Graphics.DrawEllipse(pen, circleRect);
            pen.Dispose();
        }
예제 #2
0
        protected void UpdateColor(Point mousePos)
        {
            Rectangle clientRect = ClientRectangle;

            if (mousePos.X < 0)
            {
                mousePos.X = 0;
            }
            if (mousePos.Y < 0)
            {
                mousePos.Y = 0;
            }
            if (mousePos.X > clientRect.Right - 1)
            {
                mousePos.X = clientRect.Right - 1;
            }
            if (mousePos.Y > clientRect.Bottom - 1)
            {
                mousePos.Y = clientRect.Bottom - 1;
            }

            Rectangle rect = ClientRectangle;

            _saturation = mousePos.X * 100.0 / rect.Width;
            _brightness = (rect.Height - mousePos.Y) * 100.0 / rect.Height;

            Color color = Color.FromArgb(_color.A, ColorUtils.HsbToRgb(_hue, _saturation, _brightness));

            Invalidate();

            if (color != _color)
            {
                _color = color;

                if (ValueChanged != null)
                {
                    ValueChanged(this, EventArgs.Empty);
                }
            }
        }