Renderer.Draw 方法 (IntPtr, Stroke, DrawingAttributes)

在传入其句柄的设备上下文上,用 DrawingAttributes 绘制 Stroke 对象。

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

语法

声明
<UIPermissionAttribute(SecurityAction.Demand, Window := UIPermissionWindow.SafeTopLevelWindows)> _
<SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode := True)> _
<PermissionSetAttribute(SecurityAction.InheritanceDemand, Name := "FullTrust")> _
Public Sub Draw ( _
    hdc As IntPtr, _
    stroke As Stroke, _
    da As DrawingAttributes _
)
用法
Dim instance As Renderer
Dim hdc As IntPtr
Dim stroke As Stroke
Dim da As DrawingAttributes

instance.Draw(hdc, stroke, da)
[UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.SafeTopLevelWindows)]
[SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode = true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public void Draw(
    IntPtr hdc,
    Stroke stroke,
    DrawingAttributes da
)
[UIPermissionAttribute(SecurityAction::Demand, Window = UIPermissionWindow::SafeTopLevelWindows)]
[SecurityPermissionAttribute(SecurityAction::Demand, UnmanagedCode = true)]
[PermissionSetAttribute(SecurityAction::InheritanceDemand, Name = L"FullTrust")]
public:
void Draw(
    IntPtr hdc, 
    Stroke^ stroke, 
    DrawingAttributes^ da
)
/** @attribute UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.SafeTopLevelWindows) */
/** @attribute SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode = true) */
/** @attribute PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust") */
public void Draw(
    IntPtr hdc,
    Stroke stroke,
    DrawingAttributes da
)
public function Draw(
    hdc : IntPtr, 
    stroke : Stroke, 
    da : DrawingAttributes
)

参数

  • hdc
    类型:System.IntPtr
    要在其上进行绘制的设备上下文的句柄。

备注

备注

请尽可能使用接受 Graphics 对象的合适重载,而不是接受 IntPtr 的重载。

将基于使用 SetViewTransform 方法的方式相应地调整笔的宽度。具体而言,笔宽度将乘以(或调整为)视图变换的行列式的平方根。

备注

如果未显式设置笔宽度,则默认值为 53。只有将笔宽度乘以行列式的平方根才能得到正确的边界框。边界框的高度和宽度在每个方向上扩展该数量的一半。

例如,如果笔宽度为 53,行列式的平方根为 50,边界框为 (0, 0, 1000, 1000)。根据笔宽度,边界框在每个方向上的调整计算方法为 (53 * 50) / 2,右侧和下方增加一个单位。这样,将呈现出边界框 (-1325,-1325,2326,2326)。

Renderer 对象将视区和窗口原点强制到 0,0。将保存和还原任何现有设置,但 Renderer 不使用这些设置。若要执行滚动,请使用 Renderer 对象的 GetViewTransformGetObjectTransform 方法。

ms569822.alert_security(zh-cn,VS.90).gif安全说明:

如果在部分信任环境下使用,则除了 InkCollector 需要的权限以外,此方法还需要 SecurityPermissionFlag.UnmanagedCode 权限。有关安全问题和部分信任的更多信息,请参见Security and Trust

示例

在此示例中,与 InkOverlay 对象关联的 Ink 对象中的整个 Strokes 集合将显示在不与 InkOverlay 对象自身关联的一个 Panel 上。

此外,在备用面板上显示 Stroke 对象时,将使用经过修改的 DrawingAttributes 对象。应用修改后,将反显笔画的颜色,并使其宽度加倍。然后,经过修改的 DrawingAttributes 对象将通过 da 参数传递到 Draw 方法。这不会影响原始笔画的 DrawingAttributes

' Access to the Ink.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 allStrokes As Strokes = mInkOverlay.Ink.Strokes
    ' get a graphics object for another panel
    Using g As Graphics = Me.panelForDraw.CreateGraphics()
        ' get a Renderer object. We could have used
        ' mInkOverlay.Renderer, this is another way
        Dim R As Renderer = New Renderer()
        ' get the handle to the device context
        Dim hdc As IntPtr = g.GetHdc()
        ' traverse the stroke collection
        For Each oneStroke As Stroke In allStrokes
            Dim da As DrawingAttributes = oneStroke.DrawingAttributes.Clone()
            ' invert the stroke color
            Dim cR As Byte = Not da.Color.R
            Dim cG As Byte = Not da.Color.G
            Dim cB As Byte = Not da.Color.B
            da.Color = Color.FromArgb(da.Color.A, cR, cG, cB)
            ' double the stroke width
            da.Width *= 2
            ' draw the stroke
            R.Draw(hdc, oneStroke, da)
        Next
        ' release the handle to the device context
        g.ReleaseHdc(hdc)
    End Using
End Using
// Access to the Ink.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 allStrokes = mInkOverlay.Ink.Strokes)
{
    // get a graphics object for another panel
    using (Graphics g = this.panelForDraw.CreateGraphics())
    {
        // get a Renderer object. We could have used
        // mInkOverlay.Renderer, this is another way
        Renderer R = new Renderer();
        // get the handle to the device context
        IntPtr hdc = g.GetHdc();
        // traverse the stroke collection
        foreach (Stroke oneStroke in allStrokes)
        {
            DrawingAttributes da = oneStroke.DrawingAttributes.Clone();
            // invert the stroke color
            byte cR = (byte)~(da.Color.R);
            byte cG = (byte)~(da.Color.G);
            byte cB = (byte)~(da.Color.B);
            da.Color = Color.FromArgb(da.Color.A, cR, cG, cB);
            // double the stroke width
            da.Width *= 2;
            // draw the stroke
            R.Draw(hdc, oneStroke, da);
        }
        // release the handle to the device context
        g.ReleaseHdc(hdc);
    }
}

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

Renderer 类

Renderer 成员

Draw 重载

Microsoft.Ink 命名空间

Renderer.SetViewTransform

DrawingAttributes

Strokes

Stroke