【问题标题】:Direct2d ID2D1GradientStopCollection1 - how to createDirect2d ID2D1GradientStopCollection1 - 如何创建
【发布时间】:2019-05-07 15:14:21
【问题描述】:

我正在尝试使用 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(调用该方法无效)

感谢任何帮助使其正常工作。

【问题讨论】:

  • 我可以从同一个界面创建一个 ID2D1GradientStopCollection(Direct2D 1.0 渐变停止集合) OK。但这并没有对色彩空间转换提供太多控制,并且会导致某些渐变上出现难看的色带。
  • 也许你需要指定缓冲区精度,这只是一个猜测。另一种选择是启用调试层,看看是否能提供更多信息。

标签: c++ windows direct2d


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2016-02-13
    • 1970-01-01
    • 2017-02-15
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 2016-09-14
    • 2020-11-08
    相关资源
    最近更新 更多