PathGradientBrush::GetInterpolationColors 方法获取当前为此路径渐变画笔指定的预设颜色和混合位置。
语法
Status GetInterpolationColors(
  [out] Color *presetColors,
  [out] REAL  *blendPositions,
  [in]  INT   count
);
参数
[out] presetColors
类型: 颜色*
指向接收预设颜色的数组的指针。 presetColors 数组中给定索引的颜色对应于 blendPositions 数组中同一索引的混合位置。
[out] blendPositions
类型: REAL*
指向接收混合位置的数组的指针。 每个混合位置都是一个介于 0 到 1 之间的数字,其中 0 表示渐变的边界,1 表示中心点。 介于 0 和 1 之间的混合位置指示从边界到中心点距离的一定比例的所有点集。 例如,混合位置 0.7 表示从边界到中心点方向的 70% 的所有点的集合。
[in] count
类型: INT
指定 presetColors 数组中的元素数的整数。 这与 blendPositions 数组中的元素数相同。
返回值
类型: 状态
如果该方法成功,则返回 Ok,这是 Status 枚举的元素。
如果方法失败,它将返回 Status 枚举的其他元素之一。
注解
简单路径渐变画笔有两种颜色:边界颜色和中心颜色。 使用此类画笔进行绘制时,从边界路径移动到中心点时,颜色会逐渐从边界颜色更改为中心颜色。 可以通过指定预设颜色数组和混合位置数组来创建更复杂的渐变。
在调用 PathGradientBrush::GetInterpolationColors 方法之前,必须分配两个缓冲区:一个用于保存预设颜色数组,一个用于保存混合位置数组。 可以调用 PathGradientBrush 对象的 PathGradientBrush::GetInterpolationColorCount 方法来确定这些缓冲区的所需大小。 颜色缓冲区的大小是 PathGradientBrush::GetInterpolationColorCount 的返回值乘以 size of (Color) 。 位置缓冲区的大小是 PathGradientBrush::GetInterpolationColorCount 的值乘以 size of ( REAL) 。
示例
以下示例从三角路径创建 PathGradientBrush 对象。 代码将预设颜色设置为红色、蓝色和水绿色,并将混合位置设置为 0、0.6 和 1。 该代码调用 PathGradientBrush 对象的 PathGradientBrush::GetInterpolationColorCount 方法,以获取当前为画笔设置的预设颜色数。 接下来,代码分配两个缓冲区:一个用于保存预设颜色数组,一个用于保存混合位置数组。 调用 PathGradientBrush 对象的 PathGradientBrush::GetInterpolationColors 方法时,将使用预设颜色和混合位置填充缓冲区。 最后,代码使用每种预设颜色填充一个小正方形。
VOID Example_GetInterpColors(HDC hdc)
{
   Graphics graphics(hdc);
   // Create a path gradient brush from an array of points, and
   // set the interpolation colors for that brush.
   Point points[] = {Point(100, 0), Point(200, 200), Point(0, 200)};
   PathGradientBrush pthGrBrush(points, 3);
   Color col[] = {
      Color(255, 255, 0, 0),     // red
      Color(255, 0, 0, 255),     // blue
      Color(255, 0, 255, 255)};  // aqua
   REAL pos[] = {
      0.0f,    // red at the boundary
      0.6f,    // blue 60 percent of the way from the boundary to the center
      1.0f};   // aqua at the center
   pthGrBrush.SetInterpolationColors(col, pos, 3);
   // Obtain information about the path gradient brush.
   INT colorCount = pthGrBrush.GetInterpolationColorCount();
   Color* colors = new Color[colorCount];
   REAL* positions = new REAL[colorCount];
   pthGrBrush.GetInterpolationColors(colors, positions, colorCount);
   // Fill a small square with each of the interpolation 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;
   delete [] positions; 
}
要求
| 要求 | 值 | 
|---|---|
| 最低受支持的客户端 | Windows XP、Windows 2000 Professional [仅限桌面应用] | 
| 最低受支持的服务器 | Windows 2000 Server [仅限桌面应用] | 
| 目标平台 | Windows | 
| 标头 | gdipluspath.h (包括 Gdiplus.h) | 
| Library | Gdiplus.lib | 
| DLL | Gdiplus.dll |