RecognitionAlternate.GetPropertyValue Method

RecognitionAlternate.GetPropertyValue Method

Returns the value of a specified RecognitionProperty of the RecognitionAlternate object.

Definition

Visual Basic .NET Public Function GetPropertyValue( _
ByVal g As Guid _
) As Byte()
C# public byte[] GetPropertyValue(
Guid g
);
Managed C++ public: Byte* GetPropertyValue(
Guid *g
) __gc[];

Parameters

g System.Guid. The property of the alternate to return, as a globally unique identifier (GUID) for one of the fields on the RecognitionProperty object.

Return Value

System.Byte[]. Returns the value of the property type in the form of a byte array. The return value is interpreted differently for each property type.

Remarks

Use this method to obtain property values for RecognitionProperty objects that have no corresponding helper property on the RecognitionAlternate object. Helper properties on the RecognitionAlternate object include the Confidence and LineNumber properties.

The following table describes the type of value returned in the byte array.

RecognitionProperty Type Description
ConfidenceLevel RecognitionConfidence enumeration value
HotPoint Point Leave Site object
LineMetrics Equivalent to the LATTICE_METRICS structure
LineNumber Int32 Leave Site value
MaximumStrokeCount Not used
PointsPerInch Not used
Segmentation Not used. Use the AlternatesWithConstantPropertyValues method instead.

To learn which Recognizer properties are exposed on alternates, first use the SupportedProperties property to see which properties are potentially available. These properties may or may not be passed on to the RecognitionAlternate. Then use GetPropertyValue to determine which properties are exposed on the RecognitionAlternate.

Note: Not all Recognizer properties are passed to the RecognitionAlternate object. For example, the Microsoft® gesture recognizer exposes HotPoints that can only be queried through the SupportedProperties property. The HotPoint property is not exposed on a RecognitionAlternate.

Examples

[C#]

This C# example displays the baseline used in the recognition of a Strokes collection. The GetPropertyValue method gets the line metrics from the top alternate. Then the Renderer object attached to an InkOverlay, theInkOverlay, is used to convert the ink space coordinates to pixel coordinates. Lastly, the baseline is drawn in green. This example assumes that you have already checked the SupportedProperties property to make sure that the LineMetrics property is supported.

using Microsoft.Ink;
using System.Drawing.Drawing2D;
using System.IO;
//...
    private void DrawBaseline(Strokes theStrokes)
    {
        // Get the top alternate for all the strokes
        RecognizerContext context = new RecognizerContext();
        context.Strokes = theStrokes;
        RecognitionStatus status = new RecognitionStatus();
        RecognitionResult result = context.Recognize(out status);
        RecognitionAlternate topAlternate = result.TopAlternate;

        // Get the line metrics from the top alternate
        byte [] byteArray = topAlternate.GetPropertyValue(RecognitionProperty.LineMetrics);
        using (MemoryStream stream = new MemoryStream(byteArray))
        using (BinaryReader reader = new BinaryReader(stream))
        {
            int startX = reader.ReadInt32();
            int startY = reader.ReadInt32();
            int endX = reader.ReadInt32();
            int endY = reader.ReadInt32();

            // Convert baseline to pixel coordinates
            Graphics tempGraphics = CreateGraphics();
            Point startPoint = new Point(startX, startY);
            Point endPoint = new Point(endX, endY);
            theInkOverlay.Renderer.InkSpaceToPixel(tempGraphics, ref startPoint);
            theInkOverlay.Renderer.InkSpaceToPixel(tempGraphics, ref endPoint);
            tempGraphics.DrawLine(new Pen(Color.Green), startPoint, endPoint);

            // Dispose of temporary graphics
            tempGraphics.Dispose();
        }
    }

[Visual Basic .NET]

This Microsoft Visual Basic® .NET example displays the baseline used in the recognition of a Strokes collection. The GetPropertyValue method gets the line metrics from the top alternate. Then the Renderer object attached to an InkOverlay, theInkOverlay, is used to convert the ink space coordinates to pixel coordinates. Lastly, the baseline is drawn in green. This example assumes that you have already checked the SupportedProperties property to make sure that the LineMetrics property is supported.

Imports Microsoft.Ink
Imports System.Drawing.Drawing2D
Imports System.IO
'...
    Private Sub DrawBaseline(ByVal theStrokes As Strokes)
        ' Get the top alternate for all the strokes
        Dim context As New RecognizerContext()
        context.Strokes = theStrokes
        Dim status As New RecognitionStatus()
        Dim result As RecognitionResult = context.Recognize(status)
        Dim topAlternate As RecognitionAlternate = result.TopAlternate

        ' Get the line metrics from the top alternate
        Dim byteArray() As Byte = topAlternate.GetPropertyValue(RecognitionProperty.LineMetrics)
        Dim stream As New MemoryStream(byteArray)
        Dim reader As New BinaryReader(stream)

        Dim startX As Integer = reader.ReadInt32()
        Dim startY As Integer = reader.ReadInt32()
        Dim endX As Integer = reader.ReadInt32()
        Dim endY As Integer = reader.ReadInt32()

        ' Convert baseline to pixel coordinates
        Dim tempGraphics As Graphics = CreateGraphics()
        Dim startPoint As New Point(startX, startY)
        Dim endPoint As New Point(endX, endY)
        theInkOverlay.Renderer.InkSpaceToPixel(tempGraphics, startPoint)
        theInkOverlay.Renderer.InkSpaceToPixel(tempGraphics, endPoint)
        tempGraphics.DrawLine(New Pen(Color.Green), startPoint, endPoint)

        ' Clean up
        tempGraphics.Dispose()
        reader.Close()
        stream.Close()
    End Sub

See Also

Show: