Ejemplo n.º 1
0
        /// <summary>
        /// 获取预设的渐变颜色条带列表
        /// </summary>
        /// <param name="colNum">每一行的颜色个数</param>
        /// <param name="alpha">透明度</param>
        /// <returns></returns>
        public static List <LinearColorRampInfo> GetLinearColorRamps(int colNum, int alpha)
        {
            List <LinearColorRampInfo> colorRampList = new List <LinearColorRampInfo>();

            List <Color> starts = new List <Color>();
            List <Color> ends   = new List <Color>();

            starts.AddRange(new Color[] { Color.Green, Color.White, Color.Red, Color.Red, Color.LightBlue, Color.LightCyan });
            ends.AddRange(new Color[] { Color.Blue, Color.Black, Color.Green, Color.Blue, Color.Blue, Color.Cyan });

            List <Color> defColor = GetAllDefColors();

            if (defColor.Count > 20)
            {
                int count = 0;
                int index = 0;
                int i     = 0;
                while (count < 22)
                {
                    i++;
                    if (i > 1000)
                    {
                        break;
                    }
                    if (index > defColor.Count - 2)
                    {
                        index = 0;
                    }
                    Color start = defColor[index];
                    Color end   = defColor[++index];
                    if (Math.Abs(start.R - end.R) < 50 && Math.Abs(start.B - end.B) < 50 && Math.Abs(start.G - end.G) < 50)
                    {
                        continue;
                    }
                    starts.Add(start);
                    ends.Add(end);
                    count++;
                }
            }
            for (int i = 0; i < starts.Count; i++)
            {
                LinearColorRampInfo colorRamp = new LinearColorRampInfo(starts[i], ends[i]);
                for (int j = 0; j < colNum; j++)
                {
                    int   r = starts[i].R + (ends[i].R - starts[i].R) * j / colNum;
                    int   g = starts[i].G + (ends[i].G - starts[i].G) * j / colNum;
                    int   b = starts[i].B + (ends[i].B - starts[i].B) * j / colNum;
                    Color c = Color.FromArgb(alpha, r, g, b);
                    colorRamp.ColorList.Add(c);
                }
                colorRampList.Add(colorRamp);
            }
            return(colorRampList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取预设的渐变颜色条带列表
        /// </summary>
        /// <param name="colNum">每一行的颜色个数</param>
        /// <param name="alpha">透明度</param>
        /// <returns></returns>
        public static List <LinearColorRampInfo> GetLinearColorRamps1(int colNum, int alpha)
        {
            List <LinearColorRampInfo> colorRampList = new List <LinearColorRampInfo>();

            Color[] starts = { Color.Green, Color.Black, Color.White, Color.Red, Color.Red, Color.LightBlue, Color.LightCoral, Color.LightCyan, Color.LightGray, Color.LightGreen, Color.LightPink, Color.LightSalmon, Color.LightSeaGreen, Color.LightSkyBlue, Color.LightSlateGray, Color.LightSteelBlue, Color.LightYellow };
            Color[] ends   = { Color.Blue, Color.White, Color.Black, Color.Green, Color.Blue, Color.Blue, Color.Coral, Color.Cyan, Color.Gray, Color.Green, Color.Pink, Color.Salmon, Color.SeaGreen, Color.SkyBlue, Color.SlateGray, Color.SteelBlue, Color.Yellow };
            for (int i = 0; i < starts.Length; i++)
            {
                LinearColorRampInfo colorRamp = new LinearColorRampInfo(starts[i], ends[i]);
                for (int j = 0; j < colNum; j++)
                {
                    int   r = starts[i].R + (ends[i].R - starts[i].R) * j / colNum;
                    int   g = starts[i].G + (ends[i].G - starts[i].G) * j / colNum;
                    int   b = starts[i].B + (ends[i].B - starts[i].B) * j / colNum;
                    Color c = Color.FromArgb(alpha, r, g, b);
                    colorRamp.ColorList.Add(c);
                }
                colorRampList.Add(colorRamp);
            }
            return(colorRampList);
        }