我的目标是在由ID2D1DeviceContext
提供的渲染目标中绘制几何路径。我有一个由ID2D1Factory
创建的D2D1CreateFactory
,并且以下代码失败:
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来渲染为位图。
[我的水晶球告诉我,您正在通过调用ID2D1DeviceContext
函数来创建D2D1CreateDeviceContext
实例,该函数还会创建一个新的工厂对象,然后您通过调用D2D1CreateFactory
函数导致所创建的对象不兼容来创建另一个工厂。因此,代替创建另一个工厂,您应该使用ID2D1Resource::GetFactory
查询与设备上下文相对应的工厂。