void TD() { if (!Triang.Checked) { return; } if ((int)PartCount.Value == 1) { return; } Polygon p = new Polygon(); List <Vertex> corners; if (UserDeepSearch.Checked) { MoravecCornersDetector scd = new MoravecCornersDetector(); corners = scd.ProcessImage(finalImage).Select(x => new Vertex(x.X, x.Y)).ToList(); } else { SusanCornersDetector scd = new SusanCornersDetector(); corners = scd.ProcessImage(finalImage).Select(x => new Vertex(x.X, x.Y)).ToList(); } corners.ForEach(delegate(Vertex v) { p.Add(v); }); triangulated = (Mesh)p.Triangulate(); using (Graphics graphics = Graphics.FromImage(finalImage)) { foreach (Triangle t in triangulated.Triangles) { PointF[] points = { new PointF((float)t.GetVertex(0).X, (float)t.GetVertex(0).Y), new PointF((float)t.GetVertex(1).X, (float)t.GetVertex(1).Y), new PointF((float)t.GetVertex(2).X, (float)t.GetVertex(2).Y), }; int ColR = imageBits[0, (int)points[0].Y, (int)points[0].X] + imageBits[0, (int)points[1].Y, (int)points[1].X] + imageBits[0, (int)points[2].Y, (int)points[2].X]; int ColG = imageBits[1, (int)points[0].Y, (int)points[0].X] + imageBits[1, (int)points[1].Y, (int)points[1].X] + imageBits[1, (int)points[2].Y, (int)points[2].X]; int ColB = imageBits[2, (int)points[0].Y, (int)points[0].X] + imageBits[2, (int)points[1].Y, (int)points[1].X] + imageBits[2, (int)points[2].Y, (int)points[2].X]; Brush brush = new SolidBrush(Color.FromArgb(ColR / 3, ColG / 3, ColB / 3)); graphics.FillPolygon(brush, points); } } }