Exemple #1
0
        /// <summary>
        /// 获取一个随机颜色条带
        /// </summary>
        ///<param name="colorName">颜色条带名称</param>
        /// <param name="num">颜色个数,若num大于最大颜色个数,则返回最大颜色个数的条带</param>
        /// <returns>颜色条带</returns>
        public ColorRampInfo GetRandomColorRamp(string colorName, int num)
        {
            ColorRampInfo ramp   = null;
            int           colNum = num;
            int           max    = GetRandomMaxColorNum(colorName);
            int           min    = GetRandomMinColorNum(colorName);

            if (num > max)
            {
                colNum = max;
            }
            else if (num < min)
            {
                colNum = min;
            }
            for (int i = 0; i < _randomColorRamps.Count; i++)
            {
                if (_randomColorRamps[i].ColorName == colorName && _randomColorRamps[i].Count == colNum)
                {
                    ramp = _randomColorRamps[i];
                    break;
                }
            }
            return(ramp);
        }
Exemple #2
0
        public ColorRampInfo GetRampInfo(string colorName, int num)
        {
            ColorRampInfo cri = new ColorRampInfo();

            if (_linearColorRamps.Exists(t => t.ColorName == colorName))
            {
                cri = GetLinearColorRamp(colorName, num);
            }
            else if (_randomColorRamps.Exists(t => t.ColorName == colorName))
            {
                cri = GetRandomColorRamp(colorName, num);
            }
            return(cri);
        }
Exemple #3
0
        /// <summary>
        /// 构造函数
        /// </summary>
        public ColorRampPlus()
        {
            try
            {
                string cmdStr = "select * from [ColorBrewer$]";
                string conStr = "provider=microsoft.jet.oledb.4.0;data source=" + _configPath + ";extended properties='Excel 8.0;HDR=yes;IMEX=1'";

                OleDbConnection  con     = new OleDbConnection(conStr);
                OleDbDataAdapter adapter = new OleDbDataAdapter(cmdStr, con);
                DataSet          dataSet = new DataSet();
                adapter.Fill(dataSet);
                con.Close();

                DataTable table = dataSet.Tables[0];

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string colorName  = table.Rows[i]["ColorName"].ToString();
                    string numOfColor = table.Rows[i]["NumOfColors"].ToString();
                    string type       = table.Rows[i]["Type"].ToString();

                    if (string.IsNullOrEmpty(colorName) == false && string.IsNullOrEmpty(numOfColor) == false && string.IsNullOrEmpty(type) == false)
                    {
                        int num = int.Parse(numOfColor);
                        if (num > 0)
                        {
                            ColorRampInfo info = new ColorRampInfo();
                            info.ColorName = colorName;
                            while (num > 0)
                            {
                                string R = table.Rows[i]["R"].ToString();
                                string G = table.Rows[i]["G"].ToString();
                                string B = table.Rows[i]["B"].ToString();
                                if (string.IsNullOrEmpty(R) || string.IsNullOrEmpty(G) || string.IsNullOrEmpty(B))
                                {
                                    break;
                                }
                                int r = int.Parse(R);
                                int g = int.Parse(G);
                                int b = int.Parse(B);
                                info.ColorList.Add(Color.FromArgb(r, g, b));
                                num--;
                                i++;
                            }
                            if (type.ToString() == "seq" || type.ToString() == "div")
                            {
                                _linearColorRamps.Add(info);
                            }
                            else if (type.ToString() == "qual")
                            {
                                _randomColorRamps.Add(info);
                            }
                            i--;
                        }
                    }
                }
                table.Dispose();
            }
            catch (Exception ex)
            {
            }
        }