GraphicsPath::GetBounds(Rect,constMatrix,constPen) method (gdipluspath.h)

The GraphicsPath::GetBounds method gets a bounding rectangle for this path.


Status GetBounds(
  [out] Rect         *bounds,
  [in]  const Matrix *matrix,
  [in]  const Pen    *pen


[out] bounds

Type: Rect*

Pointer to a Rect object that receives the bounding rectangle.

[in] matrix

Type: const Matrix*

Optional. Pointer to a Matrix object that specifies a transformation to be applied to this path before the bounding rectangle is calculated. This path is not permanently transformed; the transformation is used only during the process of calculating the bounding rectangle. The default value is NULL.

[in] pen

Type: const Pen*

Optional. Pointer to a Pen object that influences the size of the bounding rectangle. The bounding rectangle received in bounds will be large enough to enclose this path when the path is drawn with the pen specified by this parameter. This ensures that the path is enclosed by the bounding rectangle even if the path is drawn with a wide pen. The default value is NULL.

Return value

Type: Status

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.


The rectangle returned by this method might be larger than necessary to enclose the path as drawn by the specified pen. The rectangle is calculated to allow for the pen's miter limit at sharp corners and to allow for the pen's end caps.


The following example creates a path that has one curve and one ellipse. The code draws the path with a thick yellow pen and a thin black pen. The GraphicsPath::GetBounds method receives the address of the thick yellow pen and calculates a bounding rectangle for the path. Then the code draws the bounding rectangle.

VOID GetBoundsExample(HDC hdc)
   Graphics graphics(hdc);
   Pen blackPen(Color(255, 0, 0, 0), 1);
   Pen yellowPen(Color(255, 255, 255, 0), 10);
   Pen redPen(Color(255, 255, 0, 0), 1);

   Point pts[] = {Point(120,120), 

   // Create a path that has one curve and one ellipse.
   GraphicsPath path;
   path.AddClosedCurve(pts, 4);
   path.AddEllipse(120, 220, 100, 40);

   // Draw the path with a thick yellow pen and a thin black pen.
   graphics.DrawPath(&yellowPen, &path);
   graphics.DrawPath(&blackPen, &path);
   // Get the path's bounding rectangle.
   Rect rect;
   path.GetBounds(&rect, NULL, &yellowPen);
   graphics.DrawRectangle(&redPen, rect);  

Color(255, 0, 0, 0)Color(255, 255, 0,  0)


Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdipluspath.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See also

Clipping with a Region

Constructing and Drawing Paths

Creating a Path Gradient