PathGradientBrush::GetSurroundColors 方法 (gdipluspath.h)

PathGradientBrush::GetSurroundColors 方法获取当前为此路径渐变画笔指定的环绕颜色。

语法

Status GetSurroundColors(
  [in]      Color *colors,
  [in, out] INT   *count
);

参数

[in] colors

类型: 颜色*

指向接收环绕颜色的数组的指针。

[in, out] count

类型: INT*

指向整数的指针,该整数在输入时指定请求的颜色数。 如果方法成功,则此参数在输出时接收检索到的颜色数。 如果方法失败,则此参数不会接收值。

返回值

类型: 状态

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

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

注解

路径渐变画笔具有边界路径和中心点。 中心点设置为单一颜色,但你可以为边界上的多个点指定不同的颜色。 例如,假设你为中心颜色指定红色,并为边界上的不同点指定蓝色、绿色和黄色。 然后,当你沿着边界移动时,颜色将逐渐从蓝色更改为绿色到黄色,然后返回到蓝色。 当沿直线从边界上的任意点移动到中心点时,颜色将从该边界点的颜色更改为红色。

示例

以下示例基于由三个点的数组定义的三角路径创建 PathGradientBrush 对象。 该代码调用 PathGradientBrush 对象的 PathGradientBrush::SetSurroundColors 方法,为定义三角形的每个点指定颜色。 PathGradientBrush::GetSurroundColorCount 方法 (为画笔边界路径) 指定的颜色确定当前环绕颜色数。 接下来,代码分配一个足以接收环绕颜色数组的缓冲区,并调用 PathGradientBrush::GetSurroundColors 来填充该缓冲区。 最后,代码用画笔的每个环绕颜色填充一个小正方形。

VOID Example_GetSurColors(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a path gradient brush and set its surround colors.
   Point pts[] = {
      Point(20, 20), 
      Point(100, 20), 
      Point(100, 100)};

   Color cols[] = {
      Color(255, 255, 0, 0),  // red
      Color(255, 0, 255, 0),  // green
      Color(255, 0, 0, 0)};   // black

   INT count = 3;
   PathGradientBrush pthGrBrush(pts, 3);
   pthGrBrush.SetSurroundColors(cols, &count);
   
   // Obtain information about the path gradient brush.
   INT colorCount = pthGrBrush.GetSurroundColorCount();
   Color* colors = new Color[colorCount];
   pthGrBrush.GetSurroundColors(colors, &colorCount);

   // Fill a small square with each of the surround colors.
   SolidBrush solidBrush(Color(255, 255, 255, 255));

   for(INT j = 0; j < colorCount; ++j)
   {
      solidBrush.SetColor(colors[j]);
      graphics.FillRectangle(&solidBrush, 15*j, 0, 10, 10);
   }

   delete [] colors;
}

要求

要求
最低受支持的客户端 Windows XP、Windows 2000 Professional [仅限桌面应用]
最低受支持的服务器 Windows 2000 Server [仅限桌面应用]
目标平台 Windows
标头 gdipluspath.h (包括 Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

另请参阅

画笔和填充形状

颜色

创建路径渐变

使用颜色渐变填充形状

PathGradientBrush

PathGradientBrush::GetSurroundColorCount

PathGradientBrush::SetSurroundColors