ID2D1RenderTarget::CreateLayer (constD2D1_SIZE_F*,ID2D1Layer**) 方法 (d2d1.h)

创建可与此呈现目标及其兼容的呈现目标一起使用的层资源。

语法

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

参数

size

类型:[in] const D2D1_SIZE_F*

如果指定 (0, 0) ,则不会在层资源后面创建任何后备存储。 调用 PushLayer 时,层资源将分配到最小大小。

layer

类型:[out] ID2D1Layer**

方法返回时,包含指向指向新层的指针的指针。 此参数未经初始化即被传递。

返回值

类型: HRESULT

如果该方法成功,则返回 S_OK。 否则,它将返回 HRESULT 错误代码。

注解

层会根据需要自动调整自身大小。

示例

以下示例使用层将位图剪裁到几何掩码。 有关完整示例,请参阅 如何剪辑到几何掩码

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

要求

要求
目标平台 Windows
标头 d2d1.h
Library D2d1.lib
DLL D2d1.dll

另请参阅

ID2D1RenderTarget

层概述