Direct2d ID2D1GradientStopCollection1 - 如何创建

Direct2d ID2D1GradientStopCollection1 - how to create

我正在尝试使用 Direct2D 1.1 创建渐变。

具体来说,我正在尝试创建一个 ID2D1GradientStopCollection1。

我的代码:

ID2D1GradientStopCollection1* native = nullptr;

hr = context2_->CreateGradientStopCollection(
    (D2D1_GRADIENT_STOP*)gradientStops,
    gradientStopsCount,
    D2D1_COLOR_SPACE_SRGB,
    D2D1_COLOR_SPACE_SRGB,
    D2D1_BUFFER_PRECISION_UNKNOWN,
    D2D1_EXTEND_MODE_CLAMP,
    D2D1_COLOR_INTERPOLATION_MODE_STRAIGHT,
    &native
);

// hr returns 0x8899000a : A call to this method is invalid.

注意:context2_ 的类型为:ID2D1DeviceContext*

执行此语句失败。 hr返回错误码为0x8899000a(调用该方法无效)

任何帮助让它工作的人都感激不尽。

此方法需要特定的缓冲区精度。

hr = context2_->CreateGradientStopCollection(
    (D2D1_GRADIENT_STOP*)gradientStops,
    gradientStopsCount,
    D2D1_COLOR_SPACE_SRGB,
    D2D1_COLOR_SPACE_SRGB,
    D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB, // Buffer precision
    D2D1_EXTEND_MODE_CLAMP,
    D2D1_COLOR_INTERPOLATION_MODE_STRAIGHT,
    &native2);