Renderer.PixelToInkSpace Method

Renderer.PixelToInkSpace Method

Converts a location in pixel space coordinates to be a location in ink space coordinates by using a Graphics Leave Site object for the conversion.

Definition

Visual Basic .NET Public Sub PixelToInkSpace( _
ByVal g As Graphics, _
ByRef pt As Point _
)
C# public void PixelToInkSpace(
Graphics g,
ref Point pt
);
Managed C++ public: void PixelToInkSpace(
Graphics *g,
Point **pt
);

Parameters

g System.Drawing.Graphics. The Graphics Leave Site object to use for conversion. This generally comes from event arguments or from the System.Windows.Forms.Control.CreateGraphics Leave Site method.
pt System.Drawing.Point. The point to convert into an ink space location.

Remarks

The PixelToInkSpace method converts from pixel to ink space—where one HIMETRIC unit = .01mm, applies the inverse of the view transform, and then applies the object transform.

Examples

[C#]

This C# example function deletes all of the Stroke objects in the Ink of the InkCollector object, theInkCollector, that are to the left of the left parameter in pixel space. The example then returns a count of the deleted Stroke objects.

using System.Drawing.Drawing2D;
...
public int DeleteStrokesOnLeft(int left, InkCollector theInkCollector, Graphics g)
{
    // Convert left param from pixel space to ink space dimensions
    Point ptLeft = new Point(left, 0);
    theInkCollector.Renderer.PixelToInkSpace(g, ref ptLeft);

    // create an object to hold strokes to be deleted
    Strokes theStrokesToDelete = theInkCollector.Ink.CreateStrokes();

    foreach (Stroke theStroke in theInkCollector.Ink.Strokes)
    {
        for (int i = 0; i < theStroke.GetPoints().Length; i++)
        {
            Point ptTest = theStroke.GetPoint(i);

            // if there is a point in this stroke left of the parameter,
            if (ptTest.X < ptLeft.X)
            {
                // add this stroke to the collection to delete
                theStrokesToDelete.Add(theStroke);
                break; // out of for loop
            }
        }
    }
    if (theStrokesToDelete.Count > 0)
        theInkCollector.Ink.DeleteStrokes(theStrokesToDelete);

    return theStrokesToDelete.Count;
}
            

[VB.NET]

This Microsoft® Visual Basic® .NET example function deletes all of the Stroke objects in the Ink of the InkCollector object, theInkCollector, that are to the left of the left parameter in pixel space. The example then returns a count of the deleted Stroke objects.

Imports System.Drawing.Drawing2D
...
Public Function DeleteStrokesOnLeft(ByVal left As Integer, _
ByRef theInkCollector As InkCollector, ByVal g As Graphics)
    Dim i As Integer
    Dim ptTest As Point
    Dim ptLeft As New Point(left, 0)
    Dim theStroke As Stroke
    Dim theStrokesToDelete As Strokes
    ' convert the left parameter from pixels to ink space
    theInkCollector.Renderer.PixelToInkSpace(g, ptLeft)
    theStrokesToDelete = theInkCollector.Ink.CreateStrokes()
    For Each theStroke In theInkCollector.Ink.Strokes
        For i = 0 To theStroke.GetPoints().Length - 1
            ptTest = theStroke.GetPoint(i)
            'If the stroke has a point left of the cutoff,
            If ptTest.X < ptLeft.X Then
                ' add it to the deletion list
                theStrokesToDelete.Add(theStroke)
                Exit For 'and stop processing points
            End If
        Next
    Next
    If 0 < theStrokesToDelete.Count Then
        theInkCollector.Ink.DeleteStrokes(theStrokesToDelete)
    End If
    Return theStrokesToDelete.Count
End Function
                

See Also