Chroma-key effect
Converts a given color plus or minus a tolerance to alpha. For example, chroma-key can remove the background of an image for a green-screen overlay effect.
The CLSID for this effect is CLSID_D2D1ChromaKey.
Example image
Note
In this example, the output of the chroma-key effect is the second image with the checkerboard transparent background. The third image combines this with a background image for the final green-screen overlay.
Sample code
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();
Effect properties
The properties for the chroma-key effect are defined by the D2D1_CHROMAKEY_PROP enumeration.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows 10 [desktop apps | Windows Store apps] |
Minimum supported server | Windows 10 [desktop apps | Windows Store apps] |
Header | d2d1effects_2.h |
Library | d2d1.lib, dxguid.lib |