private void MyVisualHost1_OnSelected(Prov obj) { var vm = SimpleIoc.Default.GetInstance <MainViewModel>(); vm.SelectedProv = obj; vm.Root = new List <Prov> { obj }; }
public static System.Windows.Shapes.Path DrawPath(Contours cons, Prov prov) { var path = new System.Windows.Shapes.Path(); path.Stroke = System.Windows.Media.Brushes.Red; path.StrokeThickness = 1; path.Fill = System.Windows.Media.Brushes.Green; var group = new PathGeometry(); path.Data = group; int left = 0; int top = 0; if (prov != null) { left = prov.Rectangle.Left; top = prov.Rectangle.Top; } int i = 0; foreach (var contour in cons.Items) { if (contour.Pts.Length <= 1) { continue; } ////////////////////////////// //if (contour.Pts.Length <= 2) // return; //var subPath = new PathGeometry(); //subPath.Figures.Add(new Polygon()); var polygon = new PathFigure(); polygon.StartPoint = contour.Pts.First().ToPoint(left, top); polygon.IsClosed = true; //polygon.IsFilled = true; var seg = new PolyLineSegment(contour.Pts.Skip(1).Select(v => v.ToPoint(left, top)).ToList(), true); seg.IsSmoothJoin = true; //seg.IsStroked = false; polygon.Segments.Add(seg); //if (i == 0 || i == 2 || i == 4) //if(contour.Pts.Length>2 ) group.Figures.Add(polygon); i++; } return(path); }
public static Geometry GetGeometryByCurve(Contours cons, Prov prov) { //var path = new System.Windows.Shapes.Path(); //path.Stroke = System.Windows.Media.Brushes.Red; //path.StrokeThickness = 1; //path.Fill = System.Windows.Media.Brushes.Green; //////////////////////////////////////////////////////// ///////////////////////////////////// // Create a StreamGeometry to use to specify myPath. StreamGeometry geometry = new StreamGeometry(); geometry.FillRule = FillRule.EvenOdd; // Open a StreamGeometryContext that can be used to describe this StreamGeometry // object's contents. using (StreamGeometryContext ctx = geometry.Open()) { int left = 0; int top = 0; if (prov != null) { left = prov.Rectangle.Left; top = prov.Rectangle.Top; } foreach (var contour in cons.Items) { if (contour.Pts.Length <= 1) { continue; } //var first = beizerSegments.First().StartPoint; var firstPt = contour.Pts.First().ToPoint(left, top, 3); ////////////////////////////// // Begin the triangle at the point specified. Notice that the shape is set to // be closed so only two lines need to be specified below to make the triangle. ctx.BeginFigure(firstPt, true /* is filled */, true /* is closed */); // Draw a line to the next specified point. //ctx.LineTo(new Point(100, 100), true /* is stroked */, false /* is smooth join */); //ctx.PolyLineTo(contour.Pts.Skip(1).Select(v => v.ToPoint(left, top, 2)).ToList(), true, false); var pts1 = contour.Pts.Select(v => v.ToPoint(left, top, 3)).ToList(); var beizerSegments = InterpolationUtils.InterpolatePointWithBeizerCurves(pts1, true); if (beizerSegments != null) { var points = beizerSegments.SelectMany( v => new List <System.Windows.Point> { v.FirstControlPoint, v.SecondControlPoint, v.EndPoint }) .ToList(); ctx.PolyBezierTo(points, true, false); } } } // Freeze the geometry (make it unmodifiable) // for additional performance benefits. geometry.Freeze(); //// Specify the shape (triangle) of the Path using the StreamGeometry. //path.Data = geometry; return(geometry); }
public static unsafe ColorRangeDict GetProvinces(string file, bool isdevert = false) { ColorRangeDict dict = new ColorRangeDict(); var bmp = (Bitmap)System.Drawing.Bitmap.FromFile(file); //bmp = bmp.Scale(2); //var bmp1 = bmp.Scale(2); //var format = bmp.PixelFormat; var h = (ushort)bmp.Height; bmp.Do((p, width, height) => { var ptr = (Int32 *)p.ToPointer(); //////////////////////////////////// for (UInt16 y = 0; y < height; y++) { for (UInt16 x = 0; x < width; x++) { var val = *ptr; Prov prov; if (dict.Dict.TryGetValue(val, out prov)) { if (!isdevert) { prov.Points.Add(new Point2(x, y)); } else { prov.Points.Add(new Point2(x, (ushort)(h - y))); } } else { prov = new Prov(); prov.Color = val; if (!isdevert) { prov.Points.Add(new Point2(x, y)); } else { prov.Points.Add(new Point2(x, (ushort)(h - y))); } dict.Dict.Add(val, prov); } ptr++; } } }); foreach (var value in dict.Dict.Values) { value.CalRect(); } return(dict); }