D2D1_GRADIENT_STOP 結構 (d2d1.h)

包含漸層停駐點的位置和色彩。

語法

typedef struct D2D1_GRADIENT_STOP {
  FLOAT        position;
  D2D1_COLOR_F color;
} D2D1_GRADIENT_STOP;

成員

position

類型: FLOAT

值,表示筆刷中漸層停駐點的相對位置。 如果明確看到漸層停駐點,此值必須位於 [0.0f, 1.0f] 範圍內。

color

類型: D2D1_COLOR_F

漸層停駐點的色彩。

備註

如果漸層停駐點位於不同的位置,則可以依任何順序指定。 兩個停止點可能會共用一個位置。 在此情況下,指定的第一個停止會被視為接近 0.0f (的「低」停止) ,而後續的停止會被視為接近 1.0f) 的「較高」 (。 如果呼叫端想要在停止中間立即轉換,此行為就很有用。

一般而言,集合中至少有兩個點,不過只允許建立一個停止點。 例如,一個點位於位置 0.0f,另一個點位於位置 1.0f,而其他點則會分散在 [0, 1] 範圍中。 其中漸層進展超出 [0, 1] 的範圍,則會儲存停駐點,但可能會影響漸層。

繪製時,位置的 [0, 1] 範圍會以筆刷相依的方式對應至筆刷。 如需詳細資訊,請參閱 ID2D1LinearGradientBrushID2D1RadialGradientBrush

無法明確看到具有 [0, 1] 範圍外之位置的漸層停駐點,但它們仍會影響 [0, 1] 範圍中產生的色彩。 例如,雙停止漸層 {{0.0f, Black}, {2.0f, White}} 從 {{0.0f, Black}, {1.0f, Mid-level gray}} 以視覺方式區分。 此外,色彩會在插補之前受到限制。

範例

下列範例會建立漸層停駐點的陣列,然後使用它們來建立 ID2D1GradientStopCollection

// Create an array of gradient stops to put in the gradient stop
// collection that will be used in the gradient brush.
ID2D1GradientStopCollection *pGradientStops = NULL;

D2D1_GRADIENT_STOP gradientStops[2];
gradientStops[0].color = D2D1::ColorF(D2D1::ColorF::Yellow, 1);
gradientStops[0].position = 0.0f;
gradientStops[1].color = D2D1::ColorF(D2D1::ColorF::ForestGreen, 1);
gradientStops[1].position = 1.0f;
// Create the ID2D1GradientStopCollection from a previously
// declared array of D2D1_GRADIENT_STOP structs.
hr = m_pRenderTarget->CreateGradientStopCollection(
    gradientStops,
    2,
    D2D1_GAMMA_2_2,
    D2D1_EXTEND_MODE_CLAMP,
    &pGradientStops
    );

下一個程式碼範例會使用 ID2D1GradientStopCollection 來建立 ID2D1LinearGradientBrush

// The line that determines the direction of the gradient starts at
// the upper-left corner of the square and ends at the lower-right corner.

if (SUCCEEDED(hr))
{
    hr = m_pRenderTarget->CreateLinearGradientBrush(
        D2D1::LinearGradientBrushProperties(
            D2D1::Point2F(0, 0),
            D2D1::Point2F(150, 150)),
        pGradientStops,
        &m_pLinearGradientBrush
        );
}

規格需求

   
最低支援的用戶端 適用于 Windows Vista 的 Windows 7、Windows Vista SP2 和平臺更新 [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2008 R2、Windows Server 2008 SP2 和 Platform Update for Windows Server 2008 [傳統型應用程式 |UWP 應用程式]
標頭 d2d1.h

另請參閱

筆刷概觀

CreateGradientStopCollection

如何建立線性漸層筆刷

如何建立星形漸層筆刷

ID2D1GradientStopCollection

ID2D1LinearGradientBrush

ID2D1RadialGradientBrush