ID2D1PathGeometry和ID2D1DeviceContext的组合

问题描述 投票:0回答:1

我的目标是在由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来渲染为位图。

c++ winapi direct2d
1个回答
1
投票

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

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.