Share via


Renderer.Draw Method (Bitmap, Stroke, DrawingAttributes)

Draws the Stroke on the specified Bitmap with the specified DrawingAttributes.

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

Syntax

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

Parameters

Examples

In this example, the entire Strokes collection from an Ink object associated with an InkOverlay object is drawn on to a bitmap image that has been loaded from a file.

In addition, when drawing the Stroke objects on the bitmap image, 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.

Calling the Draw method does not display the image and the strokes. Instead, it merges the stroke rendering data with the bitmap image data in preparation for display. The bitmap image (now modified with stroke renderering data) is made visible by calling the DrawImage method of the Graphics object associated with a Panel object.

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

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