/*** Private Methods ***/ #region private async Task <Dictionary <string, ImageColor> > ProcessImage(Bitmap bitmap) { Dictionary <string, ImageColor> mColorsList = new Dictionary <string, ImageColor>(); for (int y = 0; y < bitmap.Height; y++) { for (int x = 0; x < bitmap.Width; x++) { ImageColor imgColor = new ImageColor(bitmap.GetPixel(x, y)); if (mColorsList.ContainsKey(imgColor.HtmlColor)) { ImageColor iColor = mColorsList[imgColor.HtmlColor]; iColor.Count++; mColorsList[imgColor.HtmlColor] = iColor; } else { mColorsList.Add(imgColor.HtmlColor, imgColor); } } OnRowProcessed(y, bitmap.Height); } return(mColorsList); }
private async void LoadListViewAsync(List <KeyValuePair <string, ImageColor> > sortedList) { listView1.Columns.Clear(); listView1.Columns.Add("Color"); listView1.Columns.Add("Count"); await Task.Run(() => { int q = 0; for (int i = 0; i < sortedList.Count && i < MAXCOLORSTOLIST; i++) { ImageColor imgColor = sortedList[i].Value; ListViewItem newItem = new ListViewItem(new string[] { imgColor.HtmlColor, imgColor.Count.ToString() }, null, imgColor.TextColor, imgColor.ColorValue, null); newItem.Checked = i < 6; LoadListViewAddItem(newItem); } }); }