Freigeben über


Renderer.Measure Method

Renderer.Measure Method

Calculates the Rectangle Leave Site on the device context needed to contain the Stroke object to be drawn with the Draw method of the Renderer object by using the specified DrawingAttributes.

Definition

Visual Basic .NET Public Function Measure( _
ByVal stroke As Stroke, _
ByVal da As DrawingAttributes _
) As Rectangle
C# public Rectangle Measure(
Stroke stroke,
DrawingAttributes da
);
Managed C++ public: Rectangle* Measure(
Stroke *stroke,
DrawingAttributes *da
);

Parameters

stroke Microsoft.Ink.Stroke. The Stroke object to measure.
da Microsoft.Ink.DrawingAttributes. The DrawingAttributes to use when calculating the rectangle, which override the DrawingAttributes property of the Stroke object.

Return Value

System.Drawing.Rectangle. The Rectangle Leave Site on the device context needed to contain the stroke if the stroke were drawn with the Draw method of the Renderer object. The stroke must contain x-coordinates and y-coordinates to calculate the rectangle. Otherwise, the method returns an empty rectangle.

Exceptions

ArgumentNullException Leave Site: The caller does not specify the Stroke object.
COMException Leave Site:

Remarks

This method is accurate only if you pass the same arguments to both the Measure and Draw methods.

Because the bounding box is affected by the pen width, this width is scaled appropriately for the Renderer object's view transform. To do this, the pen width is multiplied by the square root of the determinant of the view transform. The height and width of the bounding box are expanded by half this amount in each direction, and the right and bottom sides are incremented by one.

For example, consider that the pen width is originally 53, the square root of the determinant of the view transform 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).

Examples

[C#]

This C# example gets the bounding rectangle for a Stroke object, theStroke, when the pen width doubles. The Renderer object comes from the InkOverlay object, theInkOverlay.

DrawingAttributes drawingAtt = theStroke.DrawingAttributes.Clone();
drawingAtt.Width = drawingAtt.Width * 2;
Rectangle bounds = theInkOverlay.Renderer.Measure(theStroke, drawingAtt);
            

[VB.NET]

This Microsoft® Visual Basic® .NET example gets the bounding rectangle for a Stroke object, theStroke, when the pen width doubles. The Renderer object comes from the InkOverlay object, theInkOverlay.

Dim drawingAtt As DrawingAttributes = theStroke.DrawingAttributes.Clone();
drawingAtt.Width = drawingAtt.Width * 2;
Dim bounds As Rectangle = theInkOverlay.Renderer.Measure(theStroke, drawingAtt);
                

See Also