Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create ID2D1DeviceContext for IWICBitmap? (For Metro app in C++)

I can create a ID2D1RenderTarget for a IWICBitmap using the following code...

    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);

But if I want to apply ID2D1Effect to this bitmap, I can do that only if I have ID2D1DeviceContext. How do I get a ID2D1DeviceContext for a IWICBitmap?

like image 456
abix Avatar asked Oct 22 '25 15:10

abix


1 Answers

Once you have the render target created, you need to QI to the ID2D1DeviceContext. e.g.

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

Remember that the QI is increasing the ref count as well.

like image 177
Unknown1987 Avatar answered Oct 25 '25 04:10

Unknown1987



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!