Windows Dev Center

Composite effect

Use the composite effect to combine 2 or more images. This effect has 13 different composite modes. T

The composite effect accepts 2 or more inputs. When you specify 2 images, destination is the first input (index 0) and the source is the second input (index 1). If you specify more than 2 inputs the images are composited starting with the first input and the second and so on.

This effect implements all of the modes using the blending unit of the graphics processing unit (GPU).

The CLSID for this effect is CLSID_D2D1Composite.

Example image

The image here shows 2 rounded rectangles of the same size that overlap. The blue rectangle is the source and the red rectangle is the destination. The images were composited with the Source Over mode.

An example image showing 2 rounded rectangles of the same size that overlap using the Source Over mode.

Here's another example using the default mode.

Before image 1
The first source image before the effect.
Before image 2
The second image before the effect.
After
The image after the transform.

 


ComPtr<ID2D1Effect> compositeEffect;
m_d2dContext->CreateEffect(CLSID_D2D1Composite, &compositeEffect);

compositeEffect->SetInput(0, bitmap);
compositeEffect->SetInput(1, bitmapTwo);

m_d2dContext->BeginDraw();
m_d2dContext->DrawImage(compositeEffect.Get());
m_d2dContext->EndDraw();

Effect properties

Display name and index enumerationType and default valueDescription

Mode

D2D1_COMPOSITE_PROP_MODE

D2D1_COMPOSITE_MODE

D2D1_COMPOSITE_MODE_SOURCE_OVER

The mode used for the effect.

 

Mode types

The table here shows the modes of this effect. The equations listed in the table use these elements:

  • O = Output
  • S = Source
  • SA = Source Alpha
  • D = Destination
  • DA = Destination Alpha
Enumeration EquationOutput Bitmap Size
D2D1_COMPOSITE_MODE_SOURCE_OVERO = S + (1 – SA) * DUnion of source and destination bitmaps
D2D1_COMPOSITE_MODE_DESTINATION_OVERO = (1 – DA) * S + DUnion of source and destination bitmaps
D2D1_COMPOSITE_MODE_SOURCE_INO = DA * SIntersection of source and destination bitmaps
D2D1_COMPOSITE_MODE_DESTINATION_IN O = SA * DIntersection of source and destination bitmaps
D2D1_COMPOSITE_MODE_SOURCE_OUTO = (1 - DA) * SRegion of the source bitmap
D2D1_COMPOSITE_MODE_DESTINATION_OUTO = (1 - SA) * DRegion of the destination bitmap
D2D1_COMPOSITE_MODE_SOURCE_ATOPO = DA * S + (1 - SA) * DRegion of the destination bitmap
D2D1_COMPOSITE_MODE_DESTINATION_ATOPO = (1 - DA) * S + SA * DRegion of the source bitmap
D2D1_COMPOSITE_MODE_XORO = (1 - DA) * S + (1 - SA) * DUnion of source and destination bitmaps
D2D1_COMPOSITE_MODE_PLUSO = S + DUnion of source and destination bitmaps
D2D1_COMPOSITE_MODE_SOURCE_COPYO = SRegion of the source bitmap
D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPYO = S (only where source exists)Union of source and destination bitmaps. Destination is not overwritten where the source doesn't exist.
D2D1_COMPOSITE_MODE_MASK_INVERTO = (1 – D) * S + (1 – SA) * DUnion of source and destination bitmaps.The alpha values are unchanged.

 

The figure here shows an example of each of the modes with images that have an opacity of 1.0 or 0.5.

An example image of each of the modes with opacity set to 1.0 or 0.5.

Sample code

For an example of this effect, download the Direct2D composite effect modes sample.

Requirements

Minimum supported clientWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Minimum supported serverWindows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]
Headerd2d1effects.h
Libraryd2d1.lib, dxguid.lib

 

Related topics

ID2D1Effect

 

 

Community Additions

ADD
Show:
© 2015 Microsoft