Renderer.Draw 方法 (Graphics, Stroke, DrawingAttributes)
在指定的 Graphics 图面上,用 DrawingAttributes 绘制 Stroke 对象。
命名空间: Microsoft.Ink
程序集: Microsoft.Ink(在 Microsoft.Ink.dll 中)
语法
声明
Public Sub Draw ( _
g As Graphics, _
stroke As Stroke, _
da As DrawingAttributes _
)
用法
Dim instance As Renderer
Dim g As Graphics
Dim stroke As Stroke
Dim da As DrawingAttributes
instance.Draw(g, stroke, da)
public void Draw(
Graphics g,
Stroke stroke,
DrawingAttributes da
)
public:
void Draw(
Graphics^ g,
Stroke^ stroke,
DrawingAttributes^ da
)
public void Draw(
Graphics g,
Stroke stroke,
DrawingAttributes da
)
public function Draw(
g : Graphics,
stroke : Stroke,
da : DrawingAttributes
)
参数
- g
类型:System.Drawing.Graphics
要用来进行绘制的 Graphics 对象。
- stroke
类型:Microsoft.Ink.Stroke
要绘制的 Stroke 对象。
- da
类型:Microsoft.Ink.DrawingAttributes
要用于绘制的 DrawingAttributes 属性。如果指定绘制属性,这些属性将重写 Stroke 对象上的绘制属性。
备注
将基于使用 SetViewTransform 方法的方式相应地调整笔的宽度。具体而言,笔宽度将乘以(或调整为)视图变换的行列式的平方根。
备注
如果未显式设置笔宽度,则默认值为 53。只有将笔宽度乘以行列式的平方根才能得到正确的边界框。边界框的高度和宽度在每个方向上扩展该数量的一半。
例如,如果笔宽度为 53,行列式的平方根为 50,边界框为 (0, 0, 1000, 1000)。根据笔宽度,边界框在每个方向上的调整计算方法为 (53 * 50) / 2,右侧和下方增加一个单位。这样,将呈现出边界框 (-1325,-1325,2326,2326)。
Renderer 对象将视区和窗口原点强制到 0,0。将保存和还原任何现有设置,但 Renderer 不使用这些设置。若要执行滚动,请使用 Renderer 对象的 GetViewTransform 和 GetObjectTransform 方法。
示例
在此示例中,与 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()
' 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(g, oneStroke, da)
Next
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();
// 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(g, oneStroke, da);
}
}
}
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。
版本信息
.NET Framework
受以下版本支持:3.0