RGBtoHSV() public static method

In this function, R, G, and B values must be scaled to be between 0 and 1. HSV.Hue will be a value between 0 and 360, and HSV.Saturation and value are between 0 and 1. The code must scale these to be between 0 and 255 for the purposes of this application.
public static RGBtoHSV ( RGB RGB ) : HSV
RGB RGB The R(ed)G(reen)B(lue) values
return HSV
示例#1
0
        /// <summary>
        /// The timer is used to control the color wheel update from the text boxes.
        /// If we update instantly, we are unable to type, therefore allow a delay for typing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            // The tag contains the control that started the timer
            Control c = (Control)timer1.Tag;

            try
            {
                if ((Color)c.Tag == Color.White)
                {
                    this.color.Alpha = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Red)
                {
                    this.color.Red = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Green)
                {
                    this.color.Green = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Blue)
                {
                    this.color.Blue = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                this.hsvColor = ColorHandler.RGBtoHSV(this.color);
                updateBar();
            }
            catch
            {
            }
            timer1.Stop();
        }
示例#2
0
 /// <summary>
 /// The control_ lost focus.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void Control_LostFocus(object sender, EventArgs e)
 {
     // In case they leave the text box before the timer has expired, call the
     // timer1_tick to update the color wheel with the new data.
     if (timer1.Enabled)
     {
         timer1_Tick(sender, e);
     }
     hsvColor = ColorHandler.RGBtoHSV(this.color);
     updateBar();
     this.Refresh();
 }
示例#3
0
        /// <summary>
        /// The control_ text changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void Control_TextChanged(object sender, EventArgs e)
        {
            if (updatingColors)
            {
                return;
            }

            Control c = (Control)sender;

            try
            {
                if ((Color)c.Tag == Color.White)
                {
                    this.color.Alpha = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Red)
                {
                    this.color.Red = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Green)
                {
                    this.color.Green = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                if ((Color)c.Tag == Color.Blue)
                {
                    this.color.Blue = Math.Max(0, Math.Min(255, (int)(float.Parse(c.Text) * 255)));
                }

                this.hsvColor = ColorHandler.RGBtoHSV(this.color);
                updateBar();
            }
            catch
            {
            }
        }
示例#4
0
 /// <summary>
 /// The control_ lost focus.
 /// </summary>
 /// <param name="sender">
 /// The sender.
 /// </param>
 /// <param name="e">
 /// The e.
 /// </param>
 private void Control_LostFocus(object sender, EventArgs e)
 {
     hsvColor = ColorHandler.RGBtoHSV(this.color);
     updateBar();
     this.Refresh();
 }