eXodiquas
eXodiquas

Reputation: 300

UWP InkCanvas fill freehand drawn shape with color

I'm currently working on a UWP app which should allow the user to draw any shape he wants on a InkCanvas. This shapes edges are automatically completed so that there is no open space (Up to this point everything works just fine).

Now my question is: How do I automatically fill this shape with a single color (or a pattern)? I know that there is a "Point in Polygon" algorithm, but I have no idea how to implement it in the UWP InkCanvas, because I don't really get how to search for the points inside the shape without iterating over every point on the canvas.

Edit: I actually got it done by using a "Canvas" as a overlay to draw a Polyline. By using the Polyline.Fill() method it worked. But I need the same effect on the "InkCanvas" only.

Upvotes: 3

Views: 602

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

Now my question is: How do I automatically fill this shape with a single color (or a pattern)? I know that there is a "Point in Polygon" algorithm, but I have no idea how to implement it in the UWP InkCanvas

You could redraw your Ink Strokes that exist in Ink Canvas by setting new InkDrawingAttributes for InkStroke.DrawingAttributes.

private void Button_Click(object sender, RoutedEventArgs e)
{
    InkDrawingAttributes attr = new InkDrawingAttributes();
    attr.Color = Colors.Red;
    attr.IgnorePressure = true;
    attr.PenTip = PenTipShape.Circle;
    attr.Size = new Size(4, 10);
    attr.PenTipTransform = Matrix3x2.CreateRotation((float)(70 * Math.PI / 180));
    IReadOnlyList<InkStroke> InkStrokeList = MyInk.InkPresenter.StrokeContainer.GetStrokes();
    foreach (InkStroke temp in InkStrokeList)
    {
        temp.DrawingAttributes = attr; 
    }          
}

enter image description here

Upvotes: 0

Related Questions