Renderer.PixelToInkSpace 方法 (Graphics, Point%)

通过使用用于转换的 Graphics 对象,将像素空间坐标中的位置转换为墨迹空间 坐标中的位置。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Sub PixelToInkSpace ( _
    g As Graphics, _
    ByRef pt As Point _
)
用法
Dim instance As Renderer
Dim g As Graphics
Dim pt As Point

instance.PixelToInkSpace(g, pt)
public void PixelToInkSpace(
    Graphics g,
    ref Point pt
)
public:
void PixelToInkSpace(
    Graphics^ g, 
    Point% pt
)
public void PixelToInkSpace(
    Graphics g,
    /** @ref */Point pt
)
public function PixelToInkSpace(
    g : Graphics, 
    pt : Point
)

参数

备注

PixelToInkSpace 方法从像素空间转换到墨迹空间(其中一个 HIMETRIC 单位 = .01mm),并应用视图变换的倒转,然后应用对象变换。

示例

此示例演示一个方法,该方法删除传递的 InkOverlay 对象中包含参数 LeftInPixels 左侧的 Point(在像素空间中)的所有 Stroke 对象。

Private Sub DeleteStrokesByLeft(ByVal mInkOverlay As InkOverlay, ByVal LeftInPixels As Integer)
    ' Create a Point object based upon the Left parameter
    Dim ptLeft As Point = New Point(LeftInPixels, 0)

    ' Convert the point from pixel space to ink space dimensions
    ' InkOverlay.AttachedControl must be set
    Using g As Graphics = mInkOverlay.AttachedControl.CreateGraphics()
        mInkOverlay.Renderer.PixelToInkSpace(g, ptLeft)
    End Using

    ' Create a Strokes object to hold strokes to be deleted
    Dim strokesToDelete As Strokes = mInkOverlay.Ink.CreateStrokes()

    ' Access to the Strokes property returns a copy of the Strokes object.
    ' This copy must be implicitly (via using statement) or explicitly
    ' disposed of in order to avoid a memory leak.
    Using currentStrokes As Strokes = mInkOverlay.Ink.Strokes
        For Each S As Stroke In currentStrokes
            For Each strokePoint As Point In S.GetPoints()
                If (strokePoint.X < ptLeft.X) Then
                    ' Note: A particluar Stroke object might have several
                    ' points to the left of ptLeft.X - Therefore, the
                    ' following statement will be executed multiple times.
                    ' Even so, the Add method will not add the same stroke twice. 
                    strokesToDelete.Add(S)
                End If
            Next
        Next
    End Using
    If strokesToDelete.Count > 0 Then
        mInkOverlay.Ink.DeleteStrokes(strokesToDelete)
        mInkOverlay.AttachedControl.Invalidate()
    End If
    strokesToDelete.Dispose()
End Sub
private void DeleteStrokesByLeft(InkOverlay mInkOverlay, int LeftInPixels)
{
    // Create a Point object based upon the Left parameter
    Point ptLeft = new Point(LeftInPixels, 0);

    // Convert the point from pixel space to ink space dimensions
    // InkOverlay.AttachedControl must be set
    using (Graphics g = mInkOverlay.AttachedControl.CreateGraphics())
    {
        mInkOverlay.Renderer.PixelToInkSpace(g, ref ptLeft);
    }

    // Create a Strokes object to hold strokes to be deleted
    Strokes strokesToDelete = mInkOverlay.Ink.CreateStrokes();

    // Access to the Strokes property returns a copy of the Strokes object.
    // This copy must be implicitly (via using statement) or explicitly
    // disposed of in order to avoid a memory leak.
    using (Strokes currentStrokes = mInkOverlay.Ink.Strokes)
    {
        foreach (Stroke S in currentStrokes)
        {
            foreach (Point strokePoint in S.GetPoints())
            {
                if (strokePoint.X < ptLeft.X)
                {
                    // Note: A particluar Stroke object might have several
                    // points to the left of ptLeft.X - Therefore, the
                    // following statement will be executed multiple times.
                    // Even so, the Add method will not add the same stroke twice. 
                    strokesToDelete.Add(S);
                }
            }
        }
    }

    if (strokesToDelete.Count > 0)
    {
        mInkOverlay.Ink.DeleteStrokes(strokesToDelete);
        mInkOverlay.AttachedControl.Invalidate();
    }
    strokesToDelete.Dispose();
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

Renderer 类

Renderer 成员

PixelToInkSpace 重载

Microsoft.Ink 命名空间

Renderer.InkSpaceToPixel