다음을 통해 공유


RecognitionAlternate.Midline 속성

업데이트: 2007년 11월

텍스트 한 줄을 나타내는 RecognitionAlternate 개체의 중간선을 가져옵니다.

네임스페이스:  Microsoft.Ink
어셈블리:  Microsoft.Ink(Microsoft.Ink.dll)

구문

‘선언
Public ReadOnly Property Midline As Line
‘사용 방법
Dim instance As RecognitionAlternate
Dim value As Line

value = instance.Midline
public Line Midline { get; }
public:
property Line Midline {
    Line get ();
}
/** @property */
public Line get_Midline()
public function get Midline () : Line

속성 값

형식: Microsoft.Ink.Line
텍스트 한 줄을 나타내는 RecognitionAlternate 개체의 중간선입니다.

설명

중간선은 어센더를 제외한 각 문자 본체의 위쪽이 정렬되는 가상 가로줄에 해당합니다. 또한 중간선은 위쪽에 해당합니다.

참고

인식 대체 항목의 범위가 텍스트 줄에서 둘 이상의 인식 세그먼트에 걸쳐 있는 경우 이 속성은 대체 항목의 기준선에 평행한 선을 반환합니다. 중간선과 기준선 사이의 거리는 첫 번째 세그먼트 내의 해당 거리에 따라 결정됩니다.

g 매개 변수를 RecognitionProperty.Segmentation GUID(Globally Unique Identifier)로 설정하고 AlternatesWithConstantPropertyValues 메서드를 사용하면 원래 대체 항목의 세그먼트 구분에 해당하는 세그먼트 인식 대체 항목 하나의 컬렉션을 가져올 수 있습니다.

참고

인식 대체 항목의 범위가 두 줄 이상인 경우 이 속성은 COMException 예외를 throw합니다. LineAlternates 속성을 사용하면 여러 줄 인식 대체 항목에 해당하는 줄 인식 대체 항목 하나의 컬렉션을 가져올 수 있습니다.

예제

이 C# 예제에서는 ListBox 컨트롤인 theListBox 및 두 Button 컨트롤인 theRecognizeButton과 theGetDataButton이 추가된 RecognitionResultForm이라는 폼에 이벤트 처리기를 정의합니다. 또한 잉크를 수집하고 인식을 수행하는 데 사용되는 theInkCollector라는 InkCollector, theRecognizerContext라는 RecognizerContext 및 theRecognitionResult라는 RecognitionResult를 정의합니다.

theRecognizeButton의 클릭 이벤트에 대한 이벤트 처리기는 잉크 수집기의 스트로크에 대해 인식을 수행하고 인식 결과의 최상위 대체 항목에 대한 정보를 theListBox에 저장합니다.

theGetDataButton의 클릭 이벤트에 대한 이벤트 처리기는 최상위 대체 항목의 줄 대체 항목 컬렉션을 가져옵니다. 그런 다음 각 줄 대체 항목에 대한 어센더 선, 중간선, 기준선 및 디센더 선을 그립니다. 또한 줄 번호 및 각 줄 대체 항목의 신뢰도에 대한 정보를 theListBox에 저장합니다.

[C#]

// Declare ink elements and create pens.
Microsoft.Ink.InkCollector theInkCollector;
Microsoft.Ink.RecognizerContext theRecognizerContext;
Microsoft.Ink.RecognitionResult theRecognitionResult;

System.Drawing.Pen thePen1 = new Pen(Color.Red);
System.Drawing.Pen thePen2 = new Pen(Color.Orange);
System.Drawing.Pen thePen3 = new Pen(Color.Yellow);
System.Drawing.Pen thePen4 = new Pen(Color.Green);

// Event handler for the form's Load event.
private void RecognitionResultForm_Load(object sender, System.EventArgs e)
{
    // Create the ink collector.
    this.theInkCollector = new Microsoft.Ink.InkCollector(this.Handle);
    this.theInkCollector.Enabled = true;

    // Create the default recognizer context.
    this.theRecognizerContext = new Microsoft.Ink.RecognizerContext();
}

// Event handler for the "Recognize" button's Click event.
private void theRecognizeButton_Click(object sender, System.EventArgs e)
{
    // Check for ink before performing recognition.
    this.theListBox.Items.Clear();
    if (0 == this.theInkCollector.Ink.Strokes.Count)
    {
        this.theListBox.Items.Add("No ink to recognize.");
        return;
    }

    // Perform recognition on the strokes currently in the ink collector.
    Microsoft.Ink.RecognitionStatus theRecognitionStatus;
    this.theRecognizerContext.Strokes = this.theInkCollector.Ink.Strokes;
    this.theRecognitionResult =
        this.theRecognizerContext.Recognize(out theRecognitionStatus);

    // Display information about the recognition result in the list box.
    this.theListBox.Items.Add("The top alternate is: " +
        this.theRecognitionResult.TopString);
    this.theListBox.Items.Add("The top confidence is: " +
        this.theRecognitionResult.TopConfidence);
    this.theListBox.Items.Add("The number of strokes is:" +
        this.theRecognitionResult.Strokes.Count);
}

// Event handler for the "Get Data" button's Click event.
private void theGetDataButton_Click(object sender, System.EventArgs e)
{
    // Refresh the list box and check for a recognition result.
    this.theListBox.Items.Clear();
    if (null == this.theRecognitionResult)
    {
        this.theListBox.Items.Add("No recognition result available.");
        return;
    }

    // Get the line alternates collection for the top alternate.
    Microsoft.Ink.RecognitionAlternates theLineAlternates =
        this.theRecognitionResult.TopAlternate.LineAlternates;

    using (System.Drawing.Graphics g = this.CreateGraphics())
    {
        // Clear the drawing surface
        g.Clear(this.BackColor);

        // For each line alternate in the collection:
        foreach(Microsoft.Ink.RecognitionAlternate theAlternate
                    in theLineAlternates)
        {
            // Add information about the alternate to the list box.
            this.theListBox.Items.Add("The Line Number is: " +
                theAlternate.LineNumber.ToString());
            this.theListBox.Items.Add("The alternate's text is: " +
                theAlternate.ToString());
            this.theListBox.Items.Add("The number of strokes is: " +
                theAlternate.Strokes.Count);
            this.theListBox.Items.Add("The Confidence is: " +
                theAlternate.Confidence.ToString());

            // Draw the ascender, midline, baseline, and descender.
            DrawLine(g, theAlternate.Ascender, this.thePen1);
            DrawLine(g, theAlternate.Midline, this.thePen2);
            DrawLine(g, theAlternate.Baseline, this.thePen3);
            DrawLine(g, theAlternate.Descender, this.thePen4);

            this.theListBox.Items.Add(string.Empty);
        }

        // Redraw the ink.
        this.theInkCollector.Renderer.Draw(g, this.theRecognitionResult.Strokes);
    }
}

// Event handler for the form's Closed event.
private void RecognitionResultForm_Closed(object sender, System.EventArgs e)
{
    // Free the resources for the ink collector, recognizer context, and pens.
    this.theInkCollector.Dispose();
    this.theInkCollector = null;
    this.theRecognizerContext.Dispose();
    this.theRecognizerContext = null;

    this.thePen1.Dispose();
    this.thePen1 = null;
    this.thePen2.Dispose();
    this.thePen2 = null;
    this.thePen3.Dispose();
    this.thePen3 = null;
    this.thePen4.Dispose();
    this.thePen4 = null;
}

// Helper function to draw the lines.
private void DrawLine(System.Drawing.Graphics g,
    Microsoft.Ink.Line line, System.Drawing.Pen pen)
{
    System.Drawing.Point point1 = line.BeginPoint;
    System.Drawing.Point point2 = line.EndPoint;

    this.theInkCollector.Renderer.InkSpaceToPixel(g, ref point1);
    this.theInkCollector.Renderer.InkSpaceToPixel(g, ref point2);

    g.DrawLine(pen, point1, point2);
}

이 Microsoft® Visual Basic® .NET 예제에서는 ListBox 컨트롤인 theListBox 및 두 Button 컨트롤인 theRecognizeButton과 theGetDataButton이 추가된 RecognitionResultForm이라는 폼에 이벤트 처리기를 정의합니다. 또한 잉크를 수집하고 인식을 수행하는 데 사용되는 theInkCollector라는 InkCollector, theRecognizerContext라는 RecognizerContext 및 theRecognitionResult라는 RecognitionResult를 정의합니다.

theRecognizeButton의 클릭 이벤트에 대한 이벤트 처리기는 잉크 수집기의 스트로크에 대해 인식을 수행하고 인식 결과의 최상위 대체 항목에 대한 정보를 theListBox에 저장합니다.

theGetDataButton의 클릭 이벤트에 대한 이벤트 처리기는 최상위 대체 항목의 줄 대체 항목 컬렉션을 가져옵니다. 그런 다음 각 줄 대체 항목에 대한 어센더 선, 중간선, 기준선 및 디센더 선을 그립니다. 또한 줄 번호 및 각 줄 대체 항목의 신뢰도에 대한 정보를 theListBox에 저장합니다.

[Visual Basic]

    Dim theInkCollector As Microsoft.Ink.InkCollector
    Dim theRecognizerContext As Microsoft.Ink.RecognizerContext
    Dim theRecognitionResult As Microsoft.Ink.RecognitionResult

    Dim thePen1 As System.Drawing.Pen = New Pen(Color.Red)
    Dim thePen2 As System.Drawing.Pen = New Pen(Color.Orange)
    Dim thePen3 As System.Drawing.Pen = New Pen(Color.Yellow)
    Dim thePen4 As System.Drawing.Pen = New Pen(Color.Green)

    ' Event handler for the form's Load event.
    Private Sub RecognitionResultForm_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        ' Create the ink collector.
        Me.theInkCollector = New Microsoft.Ink.InkCollector(Me.Handle)
        Me.theInkCollector.Enabled = True

        ' Create the default recognizer context.
        Me.theRecognizerContext = New Microsoft.Ink.RecognizerContext
    End Sub

    ' Event handler for the "Recognize" button's Click event.
    Private Sub theRecognizeButton_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles theRecognizeButton.Click

        ' Check for ink before performing recognition.
        Me.theListBox.Items.Clear()
        If Me.theInkCollector.Ink.Strokes.Count = 0 Then
            Me.theListBox.Items.Add("No ink to recognize.")
            Return
        End If

        ' Perform recognition on the strokes currently in the ink collector.
        Dim theRecognitionStatus As Microsoft.Ink.RecognitionStatus
        Me.theRecognizerContext.Strokes = Me.theInkCollector.Ink.Strokes
        Me.theRecognitionResult = _
            Me.theRecognizerContext.Recognize(theRecognitionStatus)

        ' Display information about the recognition result in the list box.
        Me.theListBox.Items.Add("The top alternate is: " & _
                                    theRecognitionResult.TopString)
        Me.theListBox.Items.Add("The top confidence is: " & _
                                    theRecognitionResult.TopConfidence.ToString())
        Me.theListBox.Items.Add("The number of strokes is:" & _
                                    theRecognitionResult.Strokes.Count)
    End Sub

    ' Event handler for the "Get Data" button's Click event.
    Private Sub theGetDataButton_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles theGetDataButton.Click

        ' Refresh the list box and check for a recognition result.
        Me.theListBox.Items.Clear()
        If (Me.theRecognitionResult Is Nothing) Then
            Me.theListBox.Items.Add("No recognition result available.")
            Return
        End If

        ' Get the line alternates collection for the top alternate.
        Dim theLineAlternates As Microsoft.Ink.RecognitionAlternates = _
            Me.theRecognitionResult.TopAlternate.LineAlternates()

        ' Create a temporary graphics object.
        Dim g As System.Drawing.Graphics = Me.CreateGraphics()

        ' Clear the drawing surface
        g.Clear(Me.BackColor)

        ' For each line alternate in the collection:
        For Each theAlternate As Microsoft.Ink.RecognitionAlternate _
                    In theLineAlternates

            ' Add information about the alternate to the list box.
            Me.theListBox.Items.Add("The Line Number is: " & _
                theAlternate.LineNumber.ToString())
            Me.theListBox.Items.Add("The alternate's text is: " & _
                theAlternate.ToString())
            Me.theListBox.Items.Add("The number of strokes is: " & _
                theAlternate.Strokes.Count)
            Me.theListBox.Items.Add("The Confidence is: " & _
                theAlternate.Confidence.ToString())

            ' Draw the ascender, midline, baseline, and descender.
            DrawLine(g, theAlternate.Ascender, Me.thePen1)
            DrawLine(g, theAlternate.Midline, Me.thePen2)
            DrawLine(g, theAlternate.Baseline, Me.thePen3)
            DrawLine(g, theAlternate.Descender, Me.thePen4)

            Me.theListBox.Items.Add(String.Empty)
        Next

        ' Redraw the ink.
        Me.theInkCollector.Renderer.Draw(g, Me.theRecognitionResult.Strokes)

        ' Dispose of the graphics object.
        g.Dispose()
    End Sub

    ' Event handler for the form's Closed event.
    Private Sub RecognitionResultForm_Closed(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Closed

        ' Free the resources for the ink collector and recognizer context.
        Me.theInkCollector.Dispose()
        Me.theInkCollector = Nothing
        Me.theRecognizerContext.Dispose()
        Me.theRecognizerContext = Nothing

        Me.thePen1.Dispose()
        Me.thePen1 = Nothing
        Me.thePen2.Dispose()
        Me.thePen2 = Nothing
        Me.thePen3.Dispose()
        Me.thePen3 = Nothing
        Me.thePen4.Dispose()
        Me.thePen4 = Nothing
    End Sub

    ' Helper function to draw the lines.
    Private Sub DrawLine(ByVal g As System.Drawing.Graphics, _
        ByVal line As Microsoft.Ink.Line, ByVal pen As System.Drawing.Pen)

        Dim point1 As System.Drawing.Point = line.BeginPoint
        Dim point2 As System.Drawing.Point = line.EndPoint

        Me.theInkCollector.Renderer.InkSpaceToPixel(g, point1)
        Me.theInkCollector.Renderer.InkSpaceToPixel(g, point2)

        g.DrawLine(pen, point1, point2)
    End Sub

플랫폼

Windows Vista

.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

3.0에서 지원

참고 항목

참조

RecognitionAlternate 클래스

RecognitionAlternate 멤버

Microsoft.Ink 네임스페이스

Line

RecognitionAlternate.AlternatesWithConstantPropertyValues

RecognitionAlternate.LineAlternates

RecognitionAlternate.Ascender

RecognitionAlternate.Baseline

RecognitionAlternate.Descender