Renderer.PixelToInkSpace Method

Renderer.PixelToInkSpace Method

Converts an array of locations in pixel space coordinates to be an array of locations 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 pts As Point _
)
C# public void PixelToInkSpace(
Graphics g,
ref Point pts
);
Managed C++ public: void PixelToInkSpace(
Graphics *g,
Point **pts
);

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.
pts System.Drawing.Point[]. The array of points to convert into ink space locations.

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 passes in a target rectangle in pixel coordinates and an InkOverlay object, theInkOverlay, and it returns all Stroke objects in theInkOverlay whose bounds are contained within the target rectangle.

using System.Drawing.Drawing2D;
...
public Strokes GetStrokesWithinRectangle(Rectangle target, InkOverlay theInkOverlay)
{
    // Create new strokes collection
    Strokes targetStrokes = theInkOverlay.Ink.CreateStrokes();

    // Convert to ink space
    Graphics g = CreateGraphics();
    Point[] targetCorners = new Point[2]{ target.Location,
                                                    target.Location + target.Size };
    theInkOverlay.Renderer.InkSpaceToPixel(g, ref targetCorners);

    foreach (Stroke theStroke in theInkOverlay.Ink.Strokes)
    {
         Rectangle strokeBounds = theStroke.GetBoundingBox();
         if (strokeBounds.Left >= targetCorners[0].X &&
             strokeBounds.Right <= targetCorners[1].X &&
             strokeBounds.Top >= targetCorners[0].Y &&
             strokeBounds.Bottom <= targetCorners[1].Y)
         {
                 targetStrokes.Add(theStroke);
         }
    }

    g.Dispose();

    return targetStrokes;
}
            

[VB.NET]

This Microsoft® Visual Basic® .NET example function passes in a target rectangle in pixel coordinates and an InkOverlay object, theInkOverlay, and it returns all Stroke objects in theInkOverlay whose bounds are contained within the target rectangle.

Imports System.Drawing.Drawing2D
...
Public Function GetStrokesWithinRectangle(ByVal target As Rectangle, ByVal theInkOverlay As InkOverlay) _
As Strokes
    'Create new strokes collection
    Dim targetStrokes As Strokes = theInkOverlay.Ink.CreateStrokes()

    ' Convert to ink space
    Dim g As Graphics = CreateGraphics()
    Dim targetCorners(1) As Point
    targetCorners(0) = target.Location
    targetCorners(1) = New Point(target.Right, target.Bottom)
    theInkOverlay.Renderer.InkSpaceToPixel(g, targetCorners)

    ' Check each stroke
    Dim theStroke As Stroke
    For Each theStroke In theInkOverlay.Ink.Strokes
        Dim strokeBounds As Rectangle = theStroke.GetBoundingBox()
        If strokeBounds.Left >= targetCorners(0).X And _
         strokeBounds.Right <= targetCorners(1).X AndAlso _
         strokeBounds.Top >= targetCorners(0).Y AndAlso _
         strokeBounds.Bottom <= targetCorners(1).Y Then
            targetStrokes.Add(theStroke)
        End If

    Next

    g.Dispose()

    Return targetStrokes
End Function
            

See Also