LinearGradientBrush::GetInterpolationColorCount method (gdiplusbrush.h)

The LinearGradientBrush::GetInterpolationColorCount method gets the number of colors currently set to be interpolated for this linear gradient brush.

Syntax

INT GetInterpolationColorCount();

Return value

Type: INT

This method returns the number of colors to be interpolated for this linear gradient brush. If no colors have been set by using LinearGradientBrush::SetInterpolationColors, or if invalid positions were passed to LinearGradientBrush::SetInterpolationColors, then LinearGradientBrush::GetInterpolationColorCount returns 0.

Remarks

A simple linear gradient brush has two colors: a color at the starting boundary and a color at the ending boundary. When you paint with such a brush, the color changes gradually from the starting color to the ending color as you move from the starting boundary to the ending boundary. You can create a more complex gradient by using the LinearGradientBrush::SetInterpolationColors method to specify an array of colors and their corresponding blend positions to be interpolated for this linear gradient brush.

You can obtain the colors and blend positions currently set for a linear gradient brush by calling its LinearGradientBrush::GetInterpolationColors method. Before you call the LinearGradientBrush::GetInterpolationColors method, you must allocate two buffers: one to hold the array of colors and one to hold the array of blend positions. You can call the LinearGradientBrush::GetInterpolationColorCount method to determine the required size of those buffers. The size of the colors buffer is the return value of LinearGradientBrush::GetInterpolationColorCount multiplied by sizeof(Color). The size of the blend positions buffer is the value of LinearGradientBrush::GetInterpolationColorCount multiplied by sizeof( REAL).

Examples

The following example sets the colors to be interpolated for this linear gradient brush to red, blue, and green and sets the blend positions to 0, 0.3, and 1. The code calls the LinearGradientBrush::GetInterpolationColorCount method of a LinearGradientBrush object to obtain the number of colors currently set to be interpolated for the brush. Next, the code gets the colors and their positions. Then, the code fills a small rectangle with each color.

VOID Example_GetInterpColors(HDC hdc)
{
   Graphics myGraphics(hdc);

   // Create a linear gradient brush, and set the colors to be interpolated.
   Color col[] = {
      Color(255, 255, 0, 0),   // red
      Color(255, 0, 0, 255),   // blue
      Color(255, 0, 255, 0)};  // green

   REAL pos[] = {
      0.0f,   // red at the left edge
      0.3f,   // blue at 30 percent of the distance from 
              // left edge to right edge
      1.0f};  // green at the right edge

   LinearGradientBrush linGrBrush(
      Point(0, 0), 
      Point(100, 0),
      Color(255, 0, 0, 0),         // black
      Color(255, 255, 255, 255));  // white

   linGrBrush.SetInterpolationColors(col, pos, 3);

   // Obtain information about the linear gradient brush.
   INT    colorCount = 0;
   Color* colors = NULL;
   REAL*  positions = NULL;

   // How many colors have been specified to be interpolated 
   // for this brush?
   colorCount = linGrBrush.GetInterpolationColorCount();

   // Allocate a buffer large enough to hold the set of colors.
   colors = new Color[colorCount];

   // Allocate a buffer to hold the relative positions of the colors.
   positions = REAL[colorCount];

   // Get the colors and their relative positions.
   linGrBrush.GetInterpolationColors(colors, positions, colorCount);

   // Fill a small rectangle with each of the colors.
   SolidBrush* pSolidBrush;
   for(INT j = 0; j < colorCount; j++)
   {
      pSolidBrush = new SolidBrush(colors[j]);
      myGraphics.FillRectangle(pSolidBrush, 15*j, 0, 10, 10);
      delete(pSolidBrush);
   }
}

Requirements

Requirement Value
Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdiplusbrush.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See also

Brushes and Filled Shapes

Color

Creating a Linear Gradient

Filling a Shape with a Color Gradient

LinearGradientBrush

LinearGradientBrush::GetInterpolationColors

LinearGradientBrush::SetInterpolationColors

PathGradientBrush

Rect

SolidBrush