Compartilhar via


BezierPoints Property

BezierPoints Property

Gets the array of control points that represent the Bezier approximation of the stroke.

Declaration

[C++]

[propget] HRESULT get_BezierPoints ([out, retval] VARIANT* BezierPoints);

[Microsoft® Visual Basic® 6.0]

Public Property Get BezierPoints() As Variant

Property Value

VARIANT The array of control points that represent the Bezier approximation of the stroke.

This property is read-only.

For more information about the VARIANT structure, see Using the Automation Library.

Return Value

HRESULT value Description
S_OK Success.
E_POINTER Invalid parameter memory.
E_OUTOFMEMORY Cannot allocate stroke handle helper object.
E_INK_EXCEPTION An exception occurred inside the method.
E_UNEXPECTED Unexpected parameter or property type.

Remarks

The control points that the BezierPoints property returns provide a smooth approximation of the original stroke and do not necessarily lie on the stroke.

Example

[Visual Basic 6.0]

This Visual Basic 6.0 example demonstrates displaying several kinds of information that is recorded with each IInkStrokeDisp object. The calling program uses menu items to toggle the display of each strokes points, Bezier points, Bezier cusps, and self-intersections. The InkRenderer object's InkSpaceToPixelFromPoints method is used to convert the points for display. The LocatePoint function is used to interpolate the locations of the self-intersections.

Option Explicit
Option Base 0
Dim WithEvents theInkCollector As InkCollector

Private Sub Form_Load()
    Me.ScaleMode = vbPixels
    Set theInkCollector = New InkCollector
    theInkCollector.hWnd = Me.hWnd
    theInkCollector.Enabled = True
End Sub

Private Sub Form_Paint()
    Dim i As Integer
    Dim theStrokes As InkStrokes
    Set theStrokes = theInkCollector.Ink.Strokes
    Dim theStroke As IInkStrokeDisp
    For Each theStroke In theStrokes
        Dim ptBezierPoints() As Long
        ptBezierPoints = theStroke.BezierPoints
        Dim ptStrokePoints() As Long
        ptStrokePoints = theStroke.GetPoints()
        theInkCollector.Renderer.InkSpaceToPixelFromPoints Me.hDC, ptBezierPoints
        theInkCollector.Renderer.InkSpaceToPixelFromPoints Me.hDC, ptStrokePoints
        If MenuDemoCusps.Checked Then
            Dim theCusps() As Long
            theCusps = theStroke.BezierCusps
            For i = 0 To UBound(theCusps)
                'Draw a little rectangle around each Bezier cusp.
                Dim cuspX As Long
                Dim cuspY As Long
                cuspX = ptBezierPoints(theCusps(i) * 2)
                cuspY = ptBezierPoints(theCusps(i) * 2 + 1)
                Line (cuspX - 2, cuspY - 2)-Step(5, 5), vbRed, B
            Next
        End If
        If MenuDemoPoints.Checked Then
            For i = 0 To UBound(ptBezierPoints) Step 2
                'Draw a little diagonal line up from each Bezier point.
                Line (ptBezierPoints(i), ptBezierPoints(i + 1)) _
                    -Step(4, -4), vbBlue
            Next
        End If
        If MenuDemoAllPoints.Checked Then
            For i = 0 To UBound(ptStrokePoints) Step 2
                'Draw a little diagonal line down from each point.
                Line (ptStrokePoints(i), ptStrokePoints(i + 1)) _
                    -Step(-4, 5), vbMagenta
            Next
        End If
        If MenuDemoSelfIntersections.Checked Then
            Dim theSelfIntersectionLocationsArray() As Single
            theSelfIntersectionLocationsArray = theStroke.SelfIntersections
            Dim theSelfIntersectionLocation As Variant
            For Each theSelfIntersectionLocation In theSelfIntersectionLocationsArray
                Dim pt() As Long
                pt = LocatePoint(theStroke, theSelfIntersectionLocation)
                theInkCollector.Renderer.InkSpaceToPixel Me.hDC, pt(0), pt(1)
                'Draw a little circle around each intersection.
                Circle (pt(0), pt(1)), 7, vbRed
            Next
        End If
    Next
End Sub

Private Sub MenuDemoAllPoints_Click()
    MenuDemoAllPoints.Checked = Not MenuDemoAllPoints.Checked
End Sub

Private Sub MenuDemoCusps_Click()
    MenuDemoCusps.Checked = Not MenuDemoCusps.Checked
End Sub

Private Sub MenuDemoPoints_Click()
    MenuDemoPoints.Checked = Not MenuDemoPoints.Checked
End Sub

Private Sub MenuDemoSelfIntersections_Click()
    MenuDemoSelfIntersections.Checked = _
        Not MenuDemoSelfIntersections.Checked
End Sub

Private Sub MenuFileExit_Click()
    Unload Me
End Sub

'This function returns the approximate point along
'a stroke represented by a Single, as a Point.
Private Function LocatePoint( _
ByVal theStroke As IInkStrokeDisp, _
ByVal theFIndex As Single) As Long()
    Dim theResult(1) As Long
    'Get the two nearest points to the point of interest.
    Dim ptStrokePoints() As Long
    ptStrokePoints = theStroke.GetPoints(Int(theFIndex), 2)
    If UBound(ptStrokePoints) < 2 Then
        'This must be an end point.
        theResult(0) = ptStrokePoints(0)
        theResult(1) = ptStrokePoints(1)
    Else
        'Get fractional part to interpolate the distance
        'between the points.
        Dim theFraction As Single
        theFraction = theFIndex - Int(theFIndex)
        Dim deltaX As Integer
        deltaX = _
            CInt((ptStrokePoints(2) - ptStrokePoints(0)) * theFraction)
        Dim deltaY As Integer
        deltaY = _
            CInt((ptStrokePoints(3) - ptStrokePoints(1)) * theFraction)
        'Return the interpolated point.
        theResult(0) = ptStrokePoints(0) + deltaX
        theResult(1) = ptStrokePoints(1) + deltaY
    End If
    LocatePoint = theResult
End Function

Private Sub theInkCollector_Stroke( _
ByVal Cursor As MSINKAUTLib.IInkCursor, _
ByVal Stroke As MSINKAUTLib.IInkStrokeDisp, _
Cancel As Boolean)
    Refresh
End Sub

Applies To