LinearGradientBrush::GetInterpolationColorCount メソッド (gdiplusbrush.h)

LinearGradientBrush::GetInterpolationColorCount メソッドは、この線形グラデーション ブラシの補間対象として現在設定されている色の数を取得します。

構文

INT GetInterpolationColorCount();

戻り値

型: INT

このメソッドは、この線形グラデーション ブラシに補間する色の数を返します。 LinearGradientBrush::SetInterpolationColors を使用して色が設定されていない場合、または無効な位置が LinearGradientBrush::SetInterpolationColors に渡された場合、LinearGradientBrush::GetInterpolationColorCount は 0 を返します。

解説

単純な線形グラデーション ブラシには、開始境界の色と終了境界の色の 2 つの色があります。 このようなブラシでペイントすると、開始境界から終了境界に移動すると、色が開始色から終了色に徐々に変化します。 LinearGradientBrush::SetInterpolationColors メソッドを使用して、色の配列と、この線形グラデーション ブラシに補間する対応するブレンド位置を指定することで、より複雑なグラデーションを作成できます。

LinearGradientBrush::GetInterpolationColors メソッドを呼び出すことで、線形グラデーション ブラシに現在設定されている色とブレンド位置を取得できます。 LinearGradientBrush::GetInterpolationColors メソッドを呼び出す前に、色の配列を保持するバッファーとブレンド位置の配列を保持するバッファーの 2 つを割り当てる必要があります。 LinearGradientBrush::GetInterpolationColorCount メソッドを呼び出して、これらのバッファーの必要なサイズを決定できます。 色バッファーのサイズは、 LinearGradientBrush::GetInterpolationColorCountsizeof(Color) を乗算した戻り値です。 ブレンド位置バッファーのサイズは、 LinearGradientBrush::GetInterpolationColorCountsizeof( REAL) を乗算した値です。

次の使用例は、この線形グラデーション ブラシの補間する色を赤、青、緑に設定し、ブレンド位置を 0、0.3、および 1 に設定します。 このコードでは、 LinearGradientBrush オブジェクトの LinearGradientBrush::GetInterpolationColorCount メソッドを呼び出して ブラシの補間に現在設定されている色の数を取得します。 次に、コードは色とその位置を取得します。 次に、コードは小さな四角形を各色で塗りつぶします。

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);
   }
}

要件

   
サポートされている最小のクライアント Windows XP、Windows 2000 Professional [デスクトップ アプリのみ]
サポートされている最小のサーバー Windows 2000 Server [デスクトップ アプリのみ]
対象プラットフォーム Windows
ヘッダー gdiplusbrush.h (Gdiplus.h を含む)
Library Gdiplus.lib
[DLL] Gdiplus.dll

関連項目

ブラシと図形の塗りつぶし

Color

線形グラデーションの作成

色のグラデーションで図形を塗りつぶす

LinearGradientBrush

LinearGradientBrush::GetInterpolationColors

LinearGradientBrush::SetInterpolationColors

PathGradientBrush

Rect

Solidbrush