public FillPathProcessor( Configuration configuration, FillPathProcessor definition, Image <TPixel> source, Rectangle sourceRectangle) : base(configuration, source, sourceRectangle) { IPath path = definition.Region; int left = (int)MathF.Floor(path.Bounds.Left); int top = (int)MathF.Floor(path.Bounds.Top); int right = (int)MathF.Ceiling(path.Bounds.Right); int bottom = (int)MathF.Ceiling(path.Bounds.Bottom); this.bounds = Rectangle.FromLTRB(left, top, right, bottom); this.path = path.AsClosedPath(); this.definition = definition; }
public void Execute() { // Clone out our source image so we can apply various effects to it without mutating // the original yet. using Image <TPixel> clone = this.source.Clone(this.definition.Operation); // Use an image brush to apply cloned image as the source for filling the shape. // We pass explicit bounds to avoid the need to crop the clone; RectangleF bounds = this.definition.Region.Bounds; var brush = new ImageBrush(clone, bounds); // Grab hold of an image processor that can fill paths with a brush to allow it to do the hard pixel pushing for us var processor = new FillPathProcessor(this.definition.Options, brush, this.definition.Region); using IImageProcessor <TPixel> p = processor.CreatePixelSpecificProcessor(this.configuration, this.source, this.sourceRectangle); // Fill the shape using the image brush p.Execute(); }
/// <inheritdoc /> public IImageProcessor <TPixel> CreatePixelSpecificProcessor <TPixel>(Configuration configuration, Image <TPixel> source, Rectangle sourceRectangle) where TPixel : unmanaged, IPixel <TPixel> { IPath shape = this.Region.Transform(this.Options.Transform); if (shape is RectangularPolygon rectPoly) { var rectF = new RectangleF(rectPoly.Location, rectPoly.Size); var rect = (Rectangle)rectF; if (!this.Options.GraphicsOptions.Antialias || rectF == rect) { var interest = Rectangle.Intersect(sourceRectangle, rect); // Cast as in and back are the same or we are using anti-aliasing return(new FillProcessor(this.Options, this.Brush) .CreatePixelSpecificProcessor(configuration, source, interest)); } } // Clone the definition so we can pass the transformed path. var definition = new FillPathProcessor(this.Options, this.Brush, shape); return(new FillPathProcessor <TPixel>(configuration, definition, source, sourceRectangle)); }