GraphicsPath::GetBounds (RectF*,constMatrix*,constPen*) 方法 (gdipluspath.h)

GraphicsPath::GetBounds 方法获取此路径的边框。

语法

Status GetBounds(
  RectF        *bounds,
  const Matrix *matrix,
  const Pen    *pen
);

parameters

bounds

指向接收边界矩形的 RectF 对象的指针。

matrix

可选。 指向 Matrix 对象的指针,该对象指定要在计算边界矩形之前应用于此路径的转换。 此路径并非被永久变换;仅在计算边框的进程中使用变换。 默认值为 NULL。

pen

可选。 指向影响边框大小的 Pen 对象的指针。 使用此参数指定的笔绘制路径时,在边界中接收的边界矩形足够大,足以包围此路径。 这可确保路径由边界矩形包围,即使路径是使用宽笔绘制的。 默认值为 NULL。

返回值

Type:Status

如果方法成功,则返回 Ok,这是 Status 枚举的元素。

如果 方法失败,它将返回 Status 枚举的其他元素之一。

注解

此方法返回的矩形可能大于将指定笔绘制的路径括起来所需的矩形。 计算矩形是为了允许笔尖角处的斜度限制,并允许笔的端盖。

示例

以下示例创建一个具有一条曲线和一个椭圆的路径。 该代码使用一支粗黄色笔和一支细黑色笔绘制路径。 GraphicsPath::GetBounds 方法接收厚黄色笔的地址,并计算路径的边框。 然后,代码绘制边界矩形。


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), 
                  Point(200,130), 
                  Point(150,200), 
                  Point(130,180)};

   // 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.
   RectF rect;
   path.GetBounds(&rect, NULL, &yellowPen);
   graphics.DrawRectangle(&redPen, rect);  
}

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

要求

   
标头 gdipluspath.h

另请参阅

使用区域进行剪裁

构造并绘制轨迹

创建路径渐变

GraphicsPath

矩阵

路径

RectF