0
votes

I'm using Windows-universal-samples-master\Samples\InkAnalysis\InkAnalysis.sln of Microsoft's open source project. It can analysis the shape you draw, and convert to polygon or ellipse.

<Grid
<Canvas x:Name="canvas"/>
<InkCanvas x:Name="inkCanvas"/>
</Grid>

All the converted shapes are drawn to "canvas", not "inkCanvas", so they can not be saved as ink.

How to add the shapes to "inkCanvas"?

enter image description here

1
What are you asking here exactly? The shapes are shape objects which are not ink strokes, therefore cannot be added to an InkCanvas. Do you want to modify the strokes to be shaped like the shapes above and keep them as inkstrokes? - Tamás Deme
No, I want these shapes as strokes. Therefore, they can be saved to a ink file. Otherwise, when save to a ink file, these shapes are lost... - Vincent

1 Answers

3
votes

We can use InkStrokeContainer.AddStroke to add to an InkStroke object to the collection managed by the InkStrokeContainer. If the shape is polygon, We can get the point from the InkAnalysisInkDrawing.Points and set them to the InkStrokeBuilder by the CreateStrokeFromInkPoints method.

For example:

private void AddPolygonToInkCanvas(InkAnalysisInkDrawing shape)
{
    var strokeBuilder = new InkStrokeBuilder();
    var strokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();
    strokeBuilder.SetDefaultDrawingAttributes(strokes[0].DrawingAttributes);
    System.Numerics.Matrix3x2 matr = strokes[0].PointTransform;
    List<InkPoint> inkPointslist = new List<InkPoint>();
    foreach (var item in shape.Points)
    {
        var intpoint = new InkPoint(new Point(item.X, item.Y), 0.5f);
        inkPointslist.Add(intpoint);
    }
    var lastintpoint = new InkPoint(new Point(shape.Points[0].X, shape.Points[0].Y), 0.5f);
    inkPointslist.Add(lastintpoint);
    IReadOnlyList<InkPoint> inkPoints = inkPointslist;
    InkStroke stroke = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);  
    inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);
}

If the shape is ellipse, as far as I known we can not add it to the InkCanvas. We can not get the all of the ellipse, it only provides 4 points.