protected override void ProcessRecord() { if (!ShouldProcess(FileImage.FileInfo.ToString(), "Inset Image")) { return; } Image image = FileImage.Image; int insetLeft = 0; int insetRight = 0; int insetTop = 0; int insetBottom = 0; if (All != null && All.Length > 0) { insetLeft = insetRight = insetTop = insetBottom = All[0]; } if (LeftRight.HasValue) { insetLeft = insetRight = LeftRight.Value; } insetLeft = Left ?? insetLeft; insetRight = Right ?? insetRight; if (TopBottom.HasValue) { insetTop = insetBottom = TopBottom.Value; } insetTop = Top ?? insetTop; insetBottom = Bottom ?? insetBottom; int width = image.Width + insetLeft + insetRight; int height = image.Height + insetTop + insetBottom; Rgba32 insetColor = this.ParseColor(Color); PathBuilder pathBuilder = new PathBuilder(); List <PointF> outerPoints = new List <PointF>(); outerPoints.Add(new PointF(0, 0)); outerPoints.Add(new PointF(image.Width, 0)); outerPoints.Add(new PointF(image.Width, image.Height)); outerPoints.Add(new PointF(0, image.Height)); outerPoints.Add(new PointF(0, 0)); List <PointF> innerPoints = new List <PointF>(); innerPoints.Add(new PointF(insetLeft, insetTop)); innerPoints.Add(new PointF(image.Width - insetRight, insetTop)); innerPoints.Add(new PointF(image.Width - insetRight, image.Height - insetBottom)); innerPoints.Add(new PointF(insetLeft, image.Height - insetBottom)); innerPoints.Add(new PointF(insetLeft, insetTop)); pathBuilder.StartFigure(); pathBuilder.AddLines(outerPoints); pathBuilder.StartFigure(); pathBuilder.AddLines(innerPoints); pathBuilder.CloseAllFigures(); IBrush brush = this.GetBrush(Brush, Color, Background); FileImage.Image.Mutate(im => im.Fill(brush, pathBuilder.Build())); WriteObject(FileImage); }
public override IPath GetPath() { PathBuilder pb = new PathBuilder(); pb.AddLines(XY); pb.CloseFigure(); return(pb.Build()); }
public void SetOriginLeaveMatrix() { var point1 = new Vector2(10, 10); var point2 = new Vector2(10, 90); var point3 = new Vector2(50, 50); var origin = new Vector2(-50, -100); var builder = new PathBuilder(Matrix3x2.CreateScale(10)); builder.AddLines(point1, point2, point3); builder.SetOrigin(origin); // new origin is scaled by default transform builder.StartFigure(); builder.AddLines(point1, point2, point3); IPath[] shape = Assert.IsType <ComplexPolygon>(builder.Build()).Paths.ToArray(); Assert.Equal(100, shape[0].Bounds.Left); Assert.Equal(-400, shape[1].Bounds.Left); }
public override IPath GetPath() { var points = PolygonRegular.CalculateVertices(Vertices, Radius, Angle, Center); PathBuilder pb = new PathBuilder(); pb.AddLines(points); pb.CloseFigure(); return(pb.Build()); }
public void SetTransform() { var point1 = new Vector2(10, 10); var point2 = new Vector2(10, 90); var point3 = new Vector2(50, 50); var matrix = Matrix3x2.CreateTranslation(new Vector2(100, 100)); var builder = new PathBuilder(); builder.AddLines(point1, point2, point3); builder.SetTransform(matrix); builder.StartFigure(); builder.AddLines(point1, point2, point3); builder.StartFigure(); builder.ResetOrigin(); builder.AddLines(point1, point2, point3); IPath[] shape = Assert.IsType <ComplexPolygon>(builder.Build()).Paths.ToArray(); Assert.Equal(10, shape[0].Bounds.Left); Assert.Equal(110, shape[1].Bounds.Left); Assert.Equal(10, shape[0].Bounds.Left); }
public void DefaultTransform() { var point1 = new Vector2(10, 10); var point2 = new Vector2(10, 90); var point3 = new Vector2(50, 50); var matrix = Matrix3x2.CreateTranslation(new Vector2(5, 5)); var builder = new PathBuilder(matrix); builder.AddLines(point1, point2, point3); IPath shape = builder.Build(); Assert.Equal(15, shape.Bounds.Left); }
public void EnumerableAddLines() { var point1 = new Vector2(10, 10); var point2 = new Vector2(10, 90); var point3 = new Vector2(50, 50); var builder = new PathBuilder(); builder.AddLines(new List <PointF> { point1, point2, point3 }); Path shape = Assert.IsType <Path>(builder.Build()); Assert.Equal(10, shape.Bounds.Left); }
public override IPath GetPath() { var pExt = CalculateVertices(Vertices, Radius, Angle, Center); var pInt = CalculateVertices(Vertices, Radius / Ratio, Angle + 360 / 2d / Vertices, Center); PathBuilder pb = new PathBuilder(); for (int i = 0; i < (int)Vertices; i++) { pb.AddLines(pExt[i], pInt[i]); } pb.CloseFigure(); return(pb.Build()); }
private static void OutputDrawnShapeHourGlass() { // center the shape outerRadii + 10 px away from edges var sb = new PathBuilder(); // draw a 'V' sb.AddLines(new Vector2(10, 10), new Vector2(20, 20), new Vector2(30, 10)); sb.StartFigure(); // overlay rectangle sb.AddLine(new Vector2(15, 0), new Vector2(25, 0)); sb.AddLine(new Vector2(15, 30), new Vector2(25, 30)); sb.CloseFigure(); sb.Build().Translate(0, 10).Scale(10).SaveImage("drawing", $"HourGlass.png"); }
public void MultipleStartFiguresDoesntCreateEmptyPaths() { var point1 = new Vector2(10, 10); var point2 = new Vector2(10, 90); var point3 = new Vector2(50, 50); var builder = new PathBuilder(); builder.StartFigure(); builder.StartFigure(); builder.StartFigure(); builder.StartFigure(); builder.AddLines(new List <PointF> { point1, point2, point3 }); Assert.IsType <Path>(builder.Build()); }
protected override void ProcessRecord() { if (!ShouldProcess(FileImage.FileInfo.ToString(), "Fill Polygon on Image")) { return; } PathBuilder pathBuilder = new PathBuilder(); List <PointF> points = new List <PointF>(); for (int i = 0; i < Coordinates.Length; i += 2) { if (i + 1 < Coordinates.Length) { points.Add(new PointF(Coordinates[i], Coordinates[i + 1])); } } pathBuilder.StartFigure(); pathBuilder.AddLines(points); pathBuilder.CloseAllFigures(); IBrush brush = this.GetBrush(Brush, Color[0], Background); FileImage.Image.Mutate(im => im.Fill(brush, pathBuilder.Build())); WriteObject(FileImage); }
private static void DrawPath(Image canvas, GATravellingSalesmanContoller GA, PathChosen path, bool optimised) { City firstCity = GA.Cities[0]; PathBuilder pathBuilder = new PathBuilder(); var points = new List <PointF>(); points.Add(new PointF(firstCity.X, firstCity.Y)); for (int i = 0; i < path.CityIndexes.Count; i++) { City city = GA.Cities[path.CityIndexes[i]]; var p = new PointF(city.X, city.Y); points.Add(p); } pathBuilder.AddLines(points); pathBuilder.CloseFigure(); IPath spath = pathBuilder.Build(); canvas.Mutate(ctx => ctx .Draw(optimised ? Color.Blue : Color.Gray, 3, spath)); var font = SystemFonts.CreateFont("Arial", 39, FontStyle.Regular); var textGraphicsOptions = new TextGraphicsOptions(true); for (int i = 0; i < path.CityIndexes.Count; i++) { City city = GA.Cities[path.CityIndexes[i]]; var p = new PointF(city.X + (optimised ? -1 : 1) * City.ClickRadius * 4, city.Y); var glyphs = TextBuilder.GenerateGlyphs((i + 1).ToString(), p, new RendererOptions(font, textGraphicsOptions.DpiX, textGraphicsOptions.DpiY)); canvas.Mutate(ctx => ctx .Fill((GraphicsOptions)textGraphicsOptions, optimised ? Color.Blue : Color.Gray, glyphs)); } }
protected override void ProcessRecord() { if (!ShouldProcess(FileImage.FileInfo.ToString(), "Frame Image")) { return; } Image image = FileImage.Image; int padLeft = 0; int padRight = 0; int padTop = 0; int padBottom = 0; if (All != null && All.Length > 0) { padLeft = padRight = padTop = padBottom = All[0]; } if (LeftRight.HasValue) { padLeft = padRight = LeftRight.Value; } padLeft = Left ?? padLeft; padRight = Right ?? padRight; if (TopBottom.HasValue) { padTop = padBottom = TopBottom.Value; } padTop = Top ?? padTop; padBottom = Bottom ?? padBottom; int width = image.Width + padLeft + padRight; int height = image.Height + padTop + padBottom; Rgba32 frameColor = this.ParseColor(Color); using (Image clone = image.Clone(im => im.Flip(FlipMode.None))) { try { int left = padLeft; int top = padTop; width = Math.Max(width, 1); height = Math.Max(height, 1); IBrush brush = this.GetBrush(Brush, Color, Background); image.Mutate(im => im.Fill(Rgba32.White) .Pad(Math.Max(image.Width, width), Math.Max(image.Height, height), Rgba32.White) .Crop(width, height) .Opacity(0)); PathBuilder pathBuilder = new PathBuilder(); List <PointF> outerPoints = new List <PointF>(); outerPoints.Add(new PointF(0, 0)); outerPoints.Add(new PointF(image.Width, 0)); outerPoints.Add(new PointF(image.Width, image.Height)); outerPoints.Add(new PointF(0, image.Height)); outerPoints.Add(new PointF(0, 0)); padLeft = Math.Max(padLeft, 0); padRight = Math.Max(padRight, 0); padTop = Math.Max(padTop, 0); padBottom = Math.Max(padBottom, 0); List <PointF> innerPoints = new List <PointF>(); innerPoints.Add(new PointF(padLeft, padTop)); innerPoints.Add(new PointF(image.Width - padRight, padTop)); innerPoints.Add(new PointF(image.Width - padRight, image.Height - padBottom)); innerPoints.Add(new PointF(padLeft, image.Height - padBottom)); innerPoints.Add(new PointF(padLeft, padTop)); pathBuilder.StartFigure(); pathBuilder.AddLines(outerPoints); pathBuilder.StartFigure(); pathBuilder.AddLines(innerPoints); pathBuilder.CloseAllFigures(); image.Mutate(im => im.Fill(brush, pathBuilder.Build())); if (left + clone.Width > 0 && top + clone.Height > 0) { image.Mutate(im => im.DrawImage(clone, new Point(left, top), 1)); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } WriteObject(FileImage); }