Example #1
0
        private Color CalculateSelectedColor(Point p)
        {
            IColorSpaceStructure selectedColor = null;

            if (m_colorSpace is HsbColorSpace)
            {
                HSB hsb = ( HSB )m_colorSpace.Structure;

                if (m_component == 'H')
                {
                    int brightness = ( int )((( double )255 - p.Y) / 2.55);
                    int saturation = ( int )(( double )p.X / 2.55);

                    selectedColor = new HSB(hsb.Hue, saturation, brightness);
                }
                else if (m_component == 'S')
                {
                    int hue        = ( int )(p.X * (( double )360 / 255));
                    int brightness = ( int )((( double )255 - p.Y) / 2.55);

                    if (hue == 360)
                    {
                        hue = 0;
                    }

                    selectedColor = new HSB(hue, hsb.Saturation, brightness);
                }
                else if (m_component == 'B')
                {
                    int hue        = ( int )(p.X * (( double )360 / 255));
                    int saturation = ( int )((( double )255 - p.Y) / 2.55);

                    if (hue == 360)
                    {
                        hue = 0;
                    }

                    selectedColor = new HSB(hue, saturation, hsb.Brightness);
                }
            }
            else if (m_colorSpace is RgbColorSpace)
            {
                RGB rgb = ( RGB )m_colorSpace.Structure;

                if (m_component == 'R')
                {
                    selectedColor = new RGB(rgb.Red, 255 - p.Y, p.X);
                }
                else if (m_component == 'G')
                {
                    selectedColor = new RGB(255 - p.Y, rgb.Green, p.X);
                }
                else if (m_component == 'B')
                {
                    selectedColor = new RGB(p.X, 255 - p.Y, rgb.Blue);
                }
            }

            RGB crgb;
            HSB hsbSelectedColor;

            if ((hsbSelectedColor = selectedColor as HSB) != null)
            {
                crgb = ColorConverter.HsbToRgb(hsbSelectedColor);
            }
            else
            {
                crgb = ( RGB )selectedColor;
            }

            return(ColorConverter.RgbToColor(crgb));
        }
Example #2
0
        /// <summary>
        /// Converts the coordinates represented by this color space to its
        /// equivalent HEX representation.
        /// </summary>
        /// <returns>A string containing a hexadecimal value.</returns>

        internal override Color GetColor()
        {
            RGB rgb = ColorConverter.HsbToRgb(new HSB(m_csHue.Value, m_csSaturation.Value, m_csBrightness.Value));

            return(Color.FromArgb(rgb.Red, rgb.Green, rgb.Blue));
        }