PathGradientBrush::SetInterpolationColors method

The PathGradientBrush::SetInterpolationColors method sets the preset colors and the blend positions of this path gradient brush.


Status SetInterpolationColors(
  IN const Color *presetColors,
  IN const REAL  *blendPositions,
  IN INT         count



Type: const Color*

Pointer to an array of Color objects that specifies the interpolation colors for the gradient. A color of a given index in the presetColors array corresponds to the blend position of that same index in the blendPositions array.


Type: REAL*

Pointer to an array that specifies the blend positions. Each blend position is a number from 0 through 1, where 0 indicates the boundary of the gradient and 1 indicates the center point. A blend position between 0 and 1 specifies the set of all points that are a certain fraction of the distance from the boundary to the center point. For example, a blend position of 0.7 specifies the set of all points that are 70 percent of the way from the boundary to the center point.


Type: INT

Integer that specifies the number of Color objects in the presetColors array. This is the same as the number of elements in the blendPositions array.

Return Value

Type: 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.


A simple path gradient brush has two colors: a boundary color and a center color. When you paint with such a brush, the color changes gradually from the boundary color to the center color as you move from the boundary path to the center point. You can create a more complex gradient by specifying an array of preset colors and an array of blend positions.


The following example creates a PathGradientBrushobject based on a triangular path. The PathGradientBrush::SetInterpolationColors method sets the brush's preset colors to red, blue, and aqua and sets the blend positions to 0, 0, 4, and 1. The Graphics::FillRectangle method uses the path gradient brush to paint a rectangle that contains the triangular path.

VOID Example_SetInterpColors(HDC hdc)
   Graphics graphics(hdc);

   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.4f,    // blue 40 percent of the way from the boundary to the center
      1.0f};   // aqua at the center

   pthGrBrush.SetInterpolationColors(col, pos, 3);
   graphics.FillRectangle(&pthGrBrush, 0, 0, 300, 300);  


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

Brushes and Filled Shapes


Creating a Path Gradient

Filling a Shape with a Color Gradient