PathGradientBrush::GetBlend method

The PathGradientBrush::GetBlend method gets the blend factors and the corresponding blend positions currently set for this path gradient brush.


Status GetBlend(
  OUT REAL *blendFactors,
  OUT REAL *blendPositions,
  IN INT   count



Type: REAL*

Pointer to an array that receives the blend factors.


Type: REAL*

Pointer to an array that receives the blend positions.


Type: INT

Integer that specifies the number of blend factors to retrieve. Before calling the PathGradientBrush::GetBlend method of a PathGradientBrushobject, call the PathGradientBrush::GetBlendCount method of that same PathGradientBrushobject to determine the current number of blend factors. The number of blend positions retrieved is the same as the number of blend factors retrieved.

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 PathGradientBrushobject has a boundary path and a center point. When you fill an area with a path gradient brush, the color changes gradually as you move from the boundary path to the center point. By default, the color is linearly related to the distance, but you can customize the relationship between color and distance by calling the PathGradientBrush::SetBlend method.


The following example demonstrates several methods of the PathGradientBrushclass including PathGradientBrush::SetBlend, PathGradientBrush::GetBlendCount, and PathGradientBrush::GetBlend. The code creates a PathGradientBrushobject and calls the PathGradientBrush::SetBlend method to establish a set of blend factors and blend positions for the brush. Then the code calls the PathGradientBrush::GetBlendCount method to retrieve the number of blend factors. After the number of blend factors is retrieved, the code allocates two buffers: one to receive the array of blend factors and one to receive the array of blend positions. Then the code calls the PathGradientBrush::GetBlend method to retrieve the blend factors and the blend positions.

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

   // Create a path that consists of a single ellipse.
   GraphicsPath path;
   path.AddEllipse(0, 0, 200, 100);

   // Use the path to construct a brush.
   PathGradientBrush pthGrBrush(&path);

   // Set the color at the center of the path to blue.
   pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));

   // Set the color along the entire boundary of the path to aqua.
   Color colors[] = {Color(255, 0, 255, 255)};
   INT count = 1;
   pthGrBrush.SetSurroundColors(colors, &count);

   // Set blend factors and positions for the path gradient brush.
   REAL fac[] = {
      0.4f,     // 40 percent of the way from aqua to blue
      0.8f,     // 80 percent of the way from aqua to blue

   REAL pos[] = {
      0.3f,   // 30 percent of the way from the boundary to the center
      0.7f,   // 70 percent of the way from the boundary to the center

   pthGrBrush.SetBlend(fac, pos, 4);

   // Fill the ellipse with the path gradient brush.
   graphics.FillEllipse(&pthGrBrush, 0, 0, 200, 100);

   // Obtain information about the path gradient brush.
   INT blendCount = pthGrBrush.GetBlendCount();
   REAL* factors = new REAL[blendCount];
   REAL* positions = new REAL[blendCount];

   pthGrBrush.GetBlend(factors, positions, blendCount);

   for(INT j = 0; j < blendCount; ++j)
      // Inspect or use the value in factors[j].
      // Inspect or use the value in positions[j].    

   delete [] factors;
   delete [] positions; 


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







PathGradientBrush::SetCenterPoint Methods