Renderer.Draw Method (IntPtr, Stroke, DrawingAttributes)
Draws the Stroke object, with DrawingAttributes, on the device context whose handle is passed in.
Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in Microsoft.Ink.dll)
Syntax
'Declaration
<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 _
)
'Usage
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
)
public function Draw(
hdc : IntPtr,
stroke : Stroke,
da : DrawingAttributes
)
Parameters
hdc
Type: System.IntPtrThe handle of the device context on which to draw.
stroke
Type: Microsoft.Ink.StrokeThe Stroke object to draw.
da
Type: Microsoft.Ink.DrawingAttributesThe DrawingAttributes property to use for the drawing. If drawing attributes are specified, they override the drawing attributes on the Stroke object.
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.
Security Note: |
---|
If using under partial trust, this method requires SecurityPermissionFlag.UnmanagedCode permission in addition to the permissions required by InkCollector. For more information about security issues and partial trust, see Security and Trust. |
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()
' 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);
}
}
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