Share via


Renderer.Draw Method (Graphics, Stroke, DrawingAttributes)

Draws the Stroke object, with DrawingAttributes, on the specified Graphics surface.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public Sub Draw ( _
    g As Graphics, _
    stroke As Stroke, _
    da As DrawingAttributes _
)
'Usage
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 function Draw(
    g : Graphics, 
    stroke : Stroke, 
    da : DrawingAttributes
)

Parameters

Remarks

Note

Use the appropriate overload that accepts a Graphics object instead of the one that accepts an IntPtr whenever possible.

The pen width is adjusted appropriately, based on how you use SetViewTransform method. Specifically, the pen width is multiplied (or scaled) by the square root of the determinant of the view transform.

Note

If you have not set the pen width explicitly, it is 53 by default. You must multiply the pen width by the square root of the determinant to yield the correct bounding box. The height and width of the bounding box are expanded by half this amount in each direction.

For example, consider that the pen width is 53, the square root of the determinant is 50, and the bounding box is (0,0,1000,1000). The pen width adjustment to the bounding box in each direction is calculated as (53*50)/2, and the right and bottom sides are incremented by one. This results in a rendered bounding box of (-1325,-1325,2326,2326).

The Renderer object forces the viewport and window origins to 0,0. Any existing settings are saved and restored, but are not used by the Renderer. To perform scrolling, use the Renderer object's GetViewTransform and GetObjectTransform methods.

Examples

In this example, the entire Strokes collection from an Ink object associated with an InkOverlay object is displayed on a Panel other than the one associated with the InkOverlay object itself.

In addition, when displaying the Stroke objects on the alternate panel, a modified DrawingAttributes object is used. Modifications are applied that invert the color of the stroke, and double its width. The modified DrawingAttributes object is then passed to the Draw method via the da parameter. This does not affect the DrawingAttributes of the original strokes.

' 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);
        }
    }
}

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

Renderer Class

Renderer Members

Draw Overload

Microsoft.Ink Namespace

Renderer.SetViewTransform

DrawingAttributes

Strokes

Stroke