ID2D1PathGeometry 和 ID2D1DeviceContext 的组合
Combination of ID2D1PathGeometry and ID2D1DeviceContext
我的目标是在 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 来渲染成位图。
我的 crystal 球告诉我您正在通过调用 D2D1CreateDeviceContext
函数创建 ID2D1DeviceContext
实例,该函数还创建一个新的工厂对象,然后您通过调用 [=12 创建另一个工厂=] 函数导致创建的对象不兼容。因此,与其创建另一个工厂,不如使用 ID2D1Resource::GetFactory
.
查询对应于设备上下文的工厂
我的目标是在 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 来渲染成位图。
我的 crystal 球告诉我您正在通过调用 D2D1CreateDeviceContext
函数创建 ID2D1DeviceContext
实例,该函数还创建一个新的工厂对象,然后您通过调用 [=12 创建另一个工厂=] 函数导致创建的对象不兼容。因此,与其创建另一个工厂,不如使用 ID2D1Resource::GetFactory
.