public ActionResult Threads(string Id) { string pickType = Id; DateTime start = DateTime.Now; int X=(int)Session["X"]; int Y = (int)Session["Y"]; Dictionary<Color, List<ImageWorker.Point>> imageDict=new Dictionary<Color,List<ImageWorker.Point>>(); imageDict = (Dictionary<Color, List<ImageWorker.Point>>)Session["imageDic"]; double Smooth = 0.001; double XYSmooth = X * Y * Smooth; ImageWorker worker = new ImageWorker(); List<ImageWorker.ColorMul> MulNab = worker.GetColors(pickType); MyProject.ImageWorker.Picture picture = new MyProject.ImageWorker.Picture((int)Session["Y"],(int)Session["X"]); int h1 = ((Dictionary<Color, List<ImageWorker.Point>>)Session["imageDic"]).Values.Sum(x => x.Count); Session.Remove("imageDic"); Session.Add("imageDic", imageDict); int h = imageDict.Values.Sum(x => x.Count); foreach (Color c in imageDict.Keys) { MyProject.ImageWorker.ColorMul cm = worker.FindColor(c, ref MulNab); List<ImageWorker.ColorArray> t=picture.Color_array.FindAll(x => ImageWorker.CountDifferenceBetweenColors(x.color.color, cm.color) < 15); if (t.Count > 0) { picture.AddPoint(t.First().color, imageDict[c].AsReadOnly()); } else { picture.AddPoint(cm, imageDict[c].AsReadOnly()); } } DateTime findColors = DateTime.Now; string size = Session["Size"] as string; int kk = 0; switch (size) { case "Small": kk = 50; break; case "Large": kk = 100; break; case "Normal": kk = 80; break; } while (picture.Color_array.Count > kk) { ImageWorker.ColorMul reduceColor = (from x in picture.Color_array from y in picture.Color_array where x!=y orderby ImageWorker.CountDifferenceBetweenColors(x.color.color, y.color.color) select x.color).First(); List<MyProject.ImageWorker.ColorMul> cmtemp = (from x in picture.Color_array where x.color != reduceColor select x.color).ToList(); MyProject.ImageWorker.ColorMul c3 = worker.FindColor(reduceColor.color, ref cmtemp); if (c3 != null) { picture.ReduceColor(reduceColor, c3); } } List<ImageWorker.ColorMul> colorsForReduce = (from x in picture.Color_array where x.points.Count < XYSmooth select x.color).ToList(); List<MyProject.ImageWorker.ColorMul> cmtemp2 = (from x in picture.Color_array where x.points.Count >= XYSmooth select x.color).ToList(); foreach (MyProject.ImageWorker.ColorMul cc in colorsForReduce) { MyProject.ImageWorker.ColorMul c3 = worker.FindColor(cc.color, ref cmtemp2); if (c3 != null) { picture.ReduceColor(cc, c3); } } DateTime ReducingColors = DateTime.Now; ViewData["mess"] = string.Format("DictPOints:{2}FindColors: {0} ReduceColors:{1}", findColors-start, ReducingColors-findColors,h); ViewData["imageSmooth"] = picture; Session.Remove("imageSmooth"); Session.Add("imageSmooth", picture); ViewData["X"] = X; ViewData["Y"] = Y; return View(); }