HsvToRgb() public static method

Converts an HSV color specification to a System.Drawing.Color.
public static HsvToRgb ( double hue, double saturation, double value ) : Color
hue double Hue in [0, 360)
saturation double Saturation in [0, 1)
value double Value in [0, 1)
return Color
示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y">Expected to grow downward.</param>
        /// <returns></returns>
        public Color GetColor(int x, int y)
        {
            double xPrime = x - PixelRadius;
            double yPrime = PixelRadius - y;
            double radius = Math.Sqrt(Math.Pow(yPrime, 2) + Math.Pow(xPrime, 2));

            if (radius > PixelRadius)
            {
                return(Color.Transparent);
            }

            double saturation = radius / PixelRadius;
            double hue        = Math.Atan2(yPrime, xPrime) * 180.0 / Math.PI;

            if (hue < 0)
            {
                hue += 360;
            }
            return(Utility.HsvToRgb(hue, saturation, 1.0));
        }
示例#2
0
        //public void Draw(Graphics g, int x, int y)
        //{
        //    g.DrawImage(canvas, x, y);
        //}

        void GenerateSwatches()
        {
            palette = new List <List <Color> >(NumRows);
            for (int row = 0; row < NumRows; ++row)
            {
                palette.Add(new List <Color>(NumColumns));
            }

            // set primary 4 greys
            if (NumRows > 0 && NumColumns > 0)
            {
                palette[0].Add(Color.Black);
            }
            if (NumRows > 0 && NumColumns > 1)
            {
                palette[0].Add(Color.Gray);
            }
            if (NumRows > 1 && NumColumns > 0)
            {
                palette[1].Add(Color.White);
            }
            if (NumRows > 1 && NumColumns > 1)
            {
                palette[1].Add(Color.LightGray);
            }

            // all remaining colors are from all hues
            int remainingColumns = NumColumns - 2;

            for (int col = 0; col < remainingColumns; ++col)
            {
                double percent = ((double)col) / remainingColumns;
                double hue     = 360.0 * percent;
                palette[0].Add(Utility.HsvToRgb(hue, 1.0, 1.0));
                palette[1].Add(Utility.HsvToRgb(hue, 1.0, 0.5));
            }
        }