Ink​Stroke Ink​Stroke Ink​Stroke Class

Definition

A single ink stroke, including the Bézier curve parameters used for final rendering of the stroke.

public sealed class InkStroke : IInkStroke, IInkStroke2, IInkStroke3public sealed class InkStroke : IInkStroke, IInkStroke2, IInkStroke3Public NotInheritable Class InkStroke Implements IInkStroke, IInkStroke2, IInkStroke3
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

JavaScript (usage)
var inkStrokes = Windows.UI.Input.Inking.InkManager.getStrokes; var inkStroke = inkStrokes[...];
var inkStrokes = Windows.UI.Input.Inking.inkRecognitionResult.getStrokes; var inkStroke = inkStrokes[...];
var inkStrokes = Windows.UI.Input.Inking.inkStrokeContainer.getStrokes; var inkStroke = inkStrokes[...];
Note

: This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).

Examples

Here we iterate through each stroke in an InkManager and process them for final rendering using Bézier curves.

// Iterate through each stroke.
inkManager.getStrokes().forEach(
    function (stroke)
    {
        inkContext.beginPath();
        if (stroke.selected) {
            inkContext.lineWidth = stroke.drawingAttributes.size.width * 2;
            inkContext.strokeStyle = "green";
        } else {
            inkContext.lineWidth = stroke.drawingAttributes.size.width;
            inkContext.strokeStyle = "black";
        }

        // Enumerate through each line segment of the stroke.
        var first = true;

        stroke.getRenderingSegments().forEach(
            function (segment)
            {
                // Move to the starting screen location of the stroke.
                if (first)
                {
                    inkContext.moveTo(segment.position.x, segment.position.y);
                    first = false;
                }
                // Calculate the bezier curve for the segment.
                else
                {
                    inkContext.bezierCurveTo(segment.bezierControlPoint1.x,
                                             segment.bezierControlPoint1.y,
                                             segment.bezierControlPoint2.x,
                                             segment.bezierControlPoint2.y,
                                             segment.position.x, segment.position.y);
                }
            }
        );
        
        // Draw the stroke.
        inkContext.stroke();
        inkContext.closePath();
    }

Properties

BoundingRect BoundingRect BoundingRect

Gets the bounding box for the InkStroke.

public Rect BoundingRect { get; }public Rect BoundingRect { get; }Public ReadOnly Property BoundingRect As Rect
Value
Rect Rect Rect

The bounding box.

Attributes
See Also

DrawingAttributes DrawingAttributes DrawingAttributes

Gets or sets the properties associated with an InkStroke.

public InkDrawingAttributes DrawingAttributes { get; set; }public InkDrawingAttributes DrawingAttributes { get; set; }Public ReadWrite Property DrawingAttributes As InkDrawingAttributes
Attributes

Remarks

Examples

The following example demonstrates how to set a drawing attribute for a specific stroke.

Note

You cannot set the DrawingAttributes property of the stroke directly. You must create a copy of the InkDrawingAttributes of the stroke, set the desired values for that InkDrawingAttributes object, and then assign the new InkDrawingAttributes to the DrawingAttributes of the stroke, as shown here.

inkManager.getStrokes().forEach(function (stroke)
{
  var drawingAttributes = stroke.drawingAttributes;
  drawingAttributes.penTip = 
       Windows.UI.Input.Inking.PenTipShape.rectangle;
  stroke.drawingAttributes = drawingAttributes;
}

// Get the InkStroke objects.
IReadOnlyList<InkStroke> inkStrokes = inkManager.GetStrokes();
Windows.UI.Input.Inking.InkStroke cloneStroke = 
  inkStrokes.GetAt(index).Clone();
Windows.UI.Input.Inking.InkDrawingAttributes drawingAttributes = 
  cloneStroke.DrawingAttributes;
drawingAttributes.PenTip = Windows.UI.Input.Inking.PenTipShape.Rectangle;
cloneStroke.DrawingAttributes = drawingAttributes;

For the complete example, see Ink App sample.

See Also

Id Id Id

Gets the Global Unique Identifier (GUID) that identifies the ink stroke.

A GUID is assigned to each ink stroke managed by the InkPresenter.

public unsigned short Id { get; }public uint Id { get; }Public ReadOnly Property Id As uint
Value
uint uint uint

The unique identifier for the ink stroke.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

This GUID persists through serialization/deserialization of the ink stroke.

PointTransform PointTransform PointTransform

Gets or sets an affine transformation matrix to apply to the InkStroke object.

public Matrix3x2 PointTransform { get; set; }public Matrix3x2 PointTransform { get; set; }Public ReadWrite Property PointTransform As Matrix3x2
Value
Matrix3x2 Matrix3x2 Matrix3x2

The 2-D transformation matrix.

Attributes
See Also

Recognized Recognized Recognized

Gets whether the stroke is recognized.

public PlatForm::Boolean Recognized { get; }public bool Recognized { get; }Public ReadOnly Property Recognized As bool
Value
bool bool bool

True if the stroke is recognized; otherwise, false.

Attributes
See Also

Selected Selected Selected

Gets whether the stroke is selected.

public PlatForm::Boolean Selected { get; set; }public bool Selected { get; set; }Public ReadWrite Property Selected As bool
Value
bool bool bool

True if the stroke is selected; otherwise, false.

Attributes
See Also

StrokeDuration StrokeDuration StrokeDuration

Gets or sets the time taken by the user to draw a single ink stroke.

public IReference<TimeSpan> StrokeDuration { get; set; }public IReference<TimeSpan> StrokeDuration { get; set; }Public ReadWrite Property StrokeDuration As IReference<TimeSpan>
Value

The time period expressed in 100-nanosecond units.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

StrokeStartedTime StrokeStartedTime StrokeStartedTime

Gets or sets the date and time when the InkStroke was started.

public IReference<DateTime> StrokeStartedTime { get; set; }public IReference<DateTime> StrokeStartedTime { get; set; }Public ReadWrite Property StrokeStartedTime As IReference<DateTime>
Value

The date and time of day.

Attributes
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Methods

Clone() Clone() Clone()

Copies the InkStroke to another InkManager (or InkStrokeContainer ).

public InkStroke Clone()public InkStroke Clone()Public Function Clone() As InkStroke
Returns

The new stroke.

Attributes

Remarks

This method must be used with AddStroke (InkManager ) or AddStroke (InkStrokeContainer ).


inkStrokeContainer.AddStroke(stroke.Clone());
inkManager.AddStroke(stroke.Clone());
inkStrokeContainer.AddStroke(stroke.Clone());
inkManager.AddStroke(stroke.Clone());
See Also

GetInkPoints() GetInkPoints() GetInkPoints()

Gets the collection of InkPoint objects used to construct the InkStroke.

public IVectorView<InkPoint> GetInkPoints()public IVectorView<InkPoint> GetInkPoints()Public Function GetInkPoints() As IVectorView( Of InkPoint )
Returns

The collection of InkPoint objects used to construct the InkStroke.

Attributes
See Also

GetRenderingSegments() GetRenderingSegments() GetRenderingSegments()

Gets the rendering segments of the stroke.

Note

For Universal Windows app using Extensible Application Markup Language (XAML), use GetInkPoints (see remarks).

public IVectorView<InkStrokeRenderingSegment> GetRenderingSegments()public IVectorView<InkStrokeRenderingSegment> GetRenderingSegments()Public Function GetRenderingSegments() As IVectorView( Of InkStrokeRenderingSegment )
Returns

The collection of InkStrokeRenderingSegment objects.

Attributes

Remarks

If FitToCurve is set to true, this method returns an InkStrokeRenderingSegment that approximates the Bezier curve of the stroke.

If FitToCurve is set to false, this method returns a collection of InkStrokeRenderingSegment objects that represent the original raw pointer data as line segments.

For Universal Windows app using Extensible Application Markup Language (XAML), avoid changing the state of an ink stroke to retrieve the raw pointer data by using GetInkPoints instead.

See Also

See Also