예제 #1
0
        public int[] Find(int color, int count)
        {
            List <FindColorInfo> list = new List <FindColorInfo>();

            using (SqlConnection conn = this.GetConnection())
            {
                LabColor      lab;
                SqlCommand    cmd = new SqlCommand(PaletteManager.ColorSearchSql(color, ColorSearchWidth.Narrow, out lab), conn);
                SqlDataReader r   = cmd.ExecuteReader();
                while (r.Read())
                {
                    list.Add(new FindColorInfo((int)r[0],
                                               lab.Distance(new LabColor((float)(double)r[1], (float)(double)r[2], (float)(double)r[3]))));
                }
                r.Close();
                r   = null;
                cmd = null;
            }

            if (list.Count == 0)
            {
                return(null);
            }

            list.Sort(this.comparer);

            int l = count;

            if (l > list.Count)
            {
                l = count;
            }

            int[] found = new int[l];
            for (int i = 0; i < l; i++)
            {
                found[i] = list[i].Rgb;
            }

            list = null;

            return(found);
        }
예제 #2
0
        private void FindAddColors(SqlConnection conn, SortedDictionary <int, int> list, int color, ColorSearchWidth width, int mask)
        {
            LabColor      lab;
            string        sql = PaletteManager.ColorSearchSql(color, width, out lab);
            SqlCommand    cmd = new SqlCommand(sql, conn);
            SqlDataReader r   = cmd.ExecuteReader();

            while (r.Read())
            {
                int c = r.GetInt32(0);
                if (!list.ContainsKey(c))
                {
                    list.Add(c, mask);
                }
                else
                {
                    list[c] |= mask;
                }
            }
            r.Close();
            r   = null;
            cmd = null;
        }