Skip to content

How to fill outside of a polygon? #63

Answered by tocsoft
talhazengin asked this question in Q&A
Discussion options

You must be logged in to vote

The process would be to create a rectangle the size of your canvas, then clip from that rectangle the polygon you have this will give you a new polygon of the negative space, you then just fill it. this is an example extension method that can do it for you for simple colors.

public static class ImageExtensions
{
    public static IImageProcessingContext FillOuter(
        this IImageProcessingContext source,
        Color brush,
        IPath path)
    {
        var rectangle = new RectangularPolygon(PointF.Empty, source.GetCurrentSize());
        var clipped = rectangle.Clip(path);
        return source.Fill(brush, clipped);
    }
}

An example of use

Black circle on white background

var c…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@tocsoft
Comment options

Comment options

You must be logged in to vote
1 reply
@talhazengin
Comment options

Answer selected by talhazengin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants