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

在具有指定 DrawingAttributes 的指定 Bitmap 上绘制 Stroke

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

语法

声明
Public Sub Draw ( _
    destinationBitmap As Bitmap, _
    stroke As Stroke, _
    da As DrawingAttributes _
)
用法
Dim instance As Renderer
Dim destinationBitmap As Bitmap
Dim stroke As Stroke
Dim da As DrawingAttributes

instance.Draw(destinationBitmap, stroke, _
    da)
public void Draw(
    Bitmap destinationBitmap,
    Stroke stroke,
    DrawingAttributes da
)
public:
void Draw(
    Bitmap^ destinationBitmap, 
    Stroke^ stroke, 
    DrawingAttributes^ da
)
public void Draw(
    Bitmap destinationBitmap,
    Stroke stroke,
    DrawingAttributes da
)
public function Draw(
    destinationBitmap : Bitmap, 
    stroke : Stroke, 
    da : DrawingAttributes
)

参数

示例

在此示例中,将在已从文件加载的位图图像上绘制与 InkOverlay 对象关联的 Ink 对象中的整个 Strokes 集合。

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

调用 Draw 方法不会显示图像和笔画。该方法会在准备显示时将笔画呈现数据与位图图像数据合并。通过调用与 Panel 对象关联的 Graphics 对象的 DrawImage 方法,可以使位图图像(现在用笔画呈现数据修改过)可见。

' get the Bitmap object loaded from a file
' scale the image to match the panel size
Dim bgImage As Bitmap = New Bitmap(New Bitmap(imageFileName), Me.panelForDraw.Size)
' 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 Renderer object. We could have used
    ' mInkOverlay.Renderer, this is another way
    Dim R As Renderer = New Renderer()
    ' 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(bgImage, oneStroke, da)
    Next
End Using
' now display the bitmap (with the strokes) on the panel
Using g As Graphics = Me.panelForDraw.CreateGraphics()
    g.DrawImage(bgImage, 0, 0)
End Using
bgImage.Dispose()
// get the Bitmap object loaded from a file
// scale the image to match the panel size
Bitmap bgImage = new Bitmap(new Bitmap(imageFileName), this.panelForDraw.Size);
// 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 Renderer object. We could have used
    // mInkOverlay.Renderer, this is another way
    Renderer R = new Renderer();
    // 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(bgImage, oneStroke, da);
    }
}
// now display the bitmap (with the strokes) on the panel
using (Graphics g = this.panelForDraw.CreateGraphics())
{
    g.DrawImage(bgImage, 0, 0);
}
bgImage.Dispose();

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

Renderer 类

Renderer 成员

Draw 重载

Microsoft.Ink 命名空间