ID2D1RenderTarget::CreateLayer method

Creates a layer resource that can be used with this render target and its compatible render targets.

Overload list

Method Description
CreateLayer(ID2D1Layer**) Creates a layer resource that can be used with this render target and its compatible render targets.
CreateLayer(D2D1_SIZE_F,ID2D1Layer**) Creates a layer resource that can be used with this render target and its compatible render targets. The new layer has the specified initial size.
CreateLayer(D2D1_SIZE_F*,ID2D1Layer**) Creates a layer resource that can be used with this render target and its compatible render targets. The new layer has the specified initial size.

Syntax

HRESULT CreateLayer(
  const D2D1_SIZE_F *size,
  ID2D1Layer        **layer
);

Parameters

size

layer

Return Value

None

Remarks

The layer automatically resizes itself, as needed.

Examples

The following example uses a layer to clip a bitmap to a geometric mask. For the complete example, see How to Clip to a Geometric Mask.

HRESULT DemoApp::RenderWithLayer(ID2D1RenderTarget *pRT)
{
    HRESULT hr = S_OK;

    // Create a layer.
    ID2D1Layer *pLayer = NULL;
    hr = pRT->CreateLayer(NULL, &pLayer);

    if (SUCCEEDED(hr))
    {
        pRT->SetTransform(D2D1::Matrix3x2F::Translation(350, 50));

        // Push the layer with the geometric mask.
        pRT->PushLayer(
            D2D1::LayerParameters(D2D1::InfiniteRect(), m_pPathGeometry),
            pLayer
            );
            
  
        pRT->DrawBitmap(m_pOrigBitmap, D2D1::RectF(0, 0, 200, 133));
        pRT->FillRectangle(D2D1::RectF(0.f, 0.f, 25.f, 25.f), m_pSolidColorBrush);  
        pRT->FillRectangle(D2D1::RectF(25.f, 25.f, 50.f, 50.f), m_pSolidColorBrush);
        pRT->FillRectangle(D2D1::RectF(50.f, 50.f, 75.f, 75.f), m_pSolidColorBrush); 
        pRT->FillRectangle(D2D1::RectF(75.f, 75.f, 100.f, 100.f), m_pSolidColorBrush);    
        pRT->FillRectangle(D2D1::RectF(100.f, 100.f, 125.f, 125.f), m_pSolidColorBrush); 
        pRT->FillRectangle(D2D1::RectF(125.f, 125.f, 150.f, 150.f), m_pSolidColorBrush);    
        

        pRT->PopLayer();
    }

    SafeRelease(&pLayer);

    return hr;
}

Requirements

   
Target Platform Windows
Header d2d1.h
Library D2d1.lib
DLL D2d1.dll

See Also

ID2D1RenderTarget

Layers Overview