I need implement some chroma key functionality with Direct2d.
I have some code example from MSDN:
ComPtr<ID2D1Effect> chromakeyEffect;
m_d2dContext->CreateEffect(CLSID_D2D1ChromaKey, &chromakeyEffect);
chromakeyEffect->SetInput(0, bitmap);
chromaKeyEffect->SetValue(D2D1_CHROMAKEY_PROP_COLOR, {0.0f, 1.0f, 0.0f, 0.0f});
chromakeyEffect->SetValue(D2D1_CHROMAKEY_PROP_TOLERANCE, 0.2f);
chromakeyEffect->SetValue(D2D1_CHROMAKEY_PROP_INVERT_ALPHA, false);
chromakeyEffect->SetValue(D2D1_CHROMAKEY_PROP_FEATHER, false);
m_d2dContext->BeginDraw();
m_d2dContext->DrawImage(chromakeyEffect.Get());
m_d2dContext->EndDraw();
How ever, I'm little bit new in WinAPI.
Our platform have function for yield instance of ID3D11Device and I receive DX11Texture as an input.
I have two questions:
1. How can I get m_d2dContext from ID3D11Device?
2. How can I get ID2D1Image from DX11Texture?
You cannot, not at least directly.
You create a D2D factory, and from there you create a render target on top of DXGI resource, which in turn derives from certain D3D11 texture and as such belongs to certain D3D11 device. With all this together you use D2D to draw over specific D3D11 texture.
The entry point into MSDN documentation for your case is this: Direct2D and Direct3D Interoperability Overview. Specififcally for the D3D texture to D2D image scenario the suggested path is this: