我需要创建ID2D1DCRenderTarget,因为我需要与GDI兼容。我使用以下代码执行此操作:
ID2D1Factory* factory;
ID2D1DCRenderTarget* target;
ID2D1SolidColorBrush* brush;
using namespace D2D1;
D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &factory);
D2D1_RENDER_TARGET_PROPERTIES rtp = RenderTargetProperties();
rtp.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
factory->CreateDCRenderTarget(&rtp, &target);
target->CreateSolidColorBrush(ColorF(ColorF::White), &brush);
程序在最后一行崩溃。但是,当我尝试类似地创建ID2D1HwndRenderTarget时,一切正常。有谁可以帮助我?
答案 0 :(得分:0)
当我检查它时,似乎问题在于RenderTargetProperties(),如果填充了D2D1_RENDER_TARGET_PROPERTIES,例如:
D2D1_RENDER_TARGET_PROPERTIES rtp = D2D1::RenderTargetProperties(
D2D1_RENDER_TARGET_TYPE_DEFAULT,
D2D1::PixelFormat(
DXGI_FORMAT_B8G8R8A8_UNORM,
D2D1_ALPHA_MODE_IGNORE),
0,
0,
D2D1_RENDER_TARGET_USAGE_NONE,
D2D1_FEATURE_LEVEL_DEFAULT
);
一切正常。