【问题标题】:How to create ID2D1DeviceContext for IWICBitmap? (For Metro app in C++)如何为 IWICBitmap 创建 ID2D1DeviceContext? (用于 C++ 中的 Metro 应用程序)
【发布时间】:2012-07-27 05:30:25
【问题描述】:

我可以使用以下代码为 IWICBitmap 创建 ID2D1RenderTarget...

    D2D1_FACTORY_OPTIONS options;
    ZeroMemory(&options, sizeof(D2D1_FACTORY_OPTIONS));

#if defined(_DEBUG)
     // If the project is in a debug build, enable Direct2D debugging via SDK Layers
    options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
#endif

    ThrowIfFailed(D2D1CreateFactory(
            D2D1_FACTORY_TYPE_SINGLE_THREADED,
            __uuidof(ID2D1Factory1),
            &options,
            &m_d2dFactory
            ));

    D2D1_RENDER_TARGET_PROPERTIES props;
    props = D2D1::RenderTargetProperties();
    m_d2dFactory->CreateWicBitmapRenderTarget(m_pTheBitmap.Get(), &props, &m_target);

但是如果我想将 ID2D1Effect 应用到这个位图,我只能在我有 ID2D1DeviceContext 的情况下这样做。如何获取 IWICBitmap 的 ID2D1DeviceContext?

【问题讨论】:

    标签: c++ windows-8 microsoft-metro direct2d


    【解决方案1】:

    创建渲染目标后,您需要对 ID2D1DeviceContext 进行 QI。例如

    pWicRenderTarget->QueryInterface(
                          __uuidof(ID2D1DeviceContext), 
                          reinterpret_cast<void**>(&pDC)
                          );
    

    请记住,QI 也在增加引用计数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      相关资源
      最近更新 更多