ID2D1PathGeometry 和 ID2D1DeviceContext 的组合

Combination of ID2D1PathGeometry and ID2D1DeviceContext

本文关键字:组合 ID2D1DeviceContext ID2D1PathGeometry      更新时间:2023-10-16

我的目标是在ID2D1DeviceContext提供的渲染目标中绘制几何路径。 我有一个由D2D1CreateFactory创建的ID2D1Factory,以下代码失败:

CComPtr<ID2D1PathGeometry> m_pPathGeometry;
fa->CreatePathGeometry(&m_pPathGeometry);
CComQIPtr<ID2D1SolidColorBrush> b;
D2D1_COLOR_F cc = { 1.0f,1.0f,1.0f,1.0f };
pRT->CreateSolidColorBrush(cc, &b);
pRT->FillGeometry(m_pPathGeometry, b);

调用 pRT->EndDraw(( 时,我收到一条消息0x88990012 : Objects used together must be created from the same factory instance

为什么?这是否意味着路径几何体仅与使用fa->CreateHwndRenderTarget()创建的呈现器目标兼容?但我当然需要一个ID2D1DeviceContext来渲染成位图。

我的水晶球告诉我,您正在通过调用D2D1CreateDeviceContext函数来创建ID2D1DeviceContext实例,该函数也会创建一个新的工厂对象,然后通过调用导致创建对象不兼容D2D1CreateFactory函数来创建另一个工厂。因此,您应该使用ID2D1Resource::GetFactory查询与设备上下文对应的工厂,而不是创建另一个工厂。