PathGradientBrush::GetBlendCount 方法 (gdipluspath.h)

PathGradientBrush::GetBlendCount方法會取得目前為此路徑漸層筆刷設定的混合因數數目。

Syntax

INT GetBlendCount();

傳回值

類型: INT

這個方法會傳回目前為這個路徑漸層筆刷設定的混合因數數目。

備註

呼叫 PathGradientBrush::GetBlend 方法 PathGradientBrush 物件之前,您必須配置兩個緩衝區:一個接收混合因數陣列,另一個是接收混合位置的陣列。 若要判斷所需緩衝區的大小,請呼叫 PathGradientBrush::GetBlendCount 方法 PathGradientBrush 物件。 每個緩衝區) 位元組 (的大小應該是 PathGradientBrush::GetBlendCount 的傳回值乘以 sizeof ( REAL) 。

範例

下列範例示範 PathGradientBrush 類別的數種方法,包括 PathGradientBrush::SetBlendPathGradientBrush::GetBlendCountPathGradientBrush::GetBlend。 程式碼會建立 PathGradientBrush 物件,並呼叫 PathGradientBrush::SetBlend 方法來建立筆刷的一組混合因數和混合位置。 然後程式碼會呼叫 PathGradientBrush::GetBlendCount 方法來擷取混合因數的數目。 擷取混合因數數目之後,程式碼會配置兩個緩衝區:一個接收混合因數的陣列,另一個用來接收混合位置的陣列。 然後程式碼會呼叫 PathGradientBrush::GetBlend 方法來擷取混合因數和混合位置。

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.0f, 
      0.4f,     // 40 percent of the way from aqua to blue
      0.8f,     // 80 percent of the way from aqua to blue
      1.0f};

   REAL pos[] = {
      0.0f, 
      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
      1.0f};

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

需求

   
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器 Windows 2000 Server [僅限傳統型應用程式]
目標平台 Windows
標頭 gdipluspath.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

筆刷和填滿的圖形

建立路徑漸層

以色彩漸層填滿圖形

PathGradientBrush

PathGradientBrush::GetBlend

PathGradientBrush::SetBlend