Direct2d ID2D1GradientStopCollection1 - how to create

0

I'm trying to create a gradient with Direct2D 1.1.

Specifically, I'm trying to create an ID2D1GradientStopCollection1.

my code:

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.

Note: context2_ is of type: ID2D1DeviceContext*

Executing this statement fails. The error code returned in hr is 0x8899000a (A call to this method is invalid.)

Any help getting this to work appreciated.

c++
windows
direct2d
asked on Stack Overflow Dec 6, 2018 by Jeff McClintock • edited Dec 6, 2018 by Jeff McClintock

1 Answer

0

This method requires a specific buffer precision.

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);
answered on Stack Overflow Mar 14, 2019 by Jeff McClintock

User contributions licensed under CC BY-SA 3.0