ID2D1RenderTarget::Clear 方法

將繪圖區域清除為指定的色彩。

多載清單

方法 描述
Clear(D2D1_COLOR_F*) 將繪圖區域清除為指定的色彩。
Clear(D2D1_COLOR_F& 將繪圖區域清除為指定的色彩。

備註

Direct2D 會將 clearColor 解譯為直 Alpha(非預乘)。 如果轉譯目標的 Alpha 模式D2D1_ALPHA_MODE_IGNORE,則會忽略 clearColorAlpha 色板,並以 1.0f 取代 (完全不透明)。

如果轉譯目標具有作用中的剪輯(由 PushAxisAlignedClip 指定),則清除命令只會套用至剪輯區域內的區域。

範例

下列範例會 使用 Clear 方法來建立白色背景,再轉譯其他內容。

//  Called whenever the application needs to display the client
//  window. This method writes "Hello, World"
//
//  Note that this function will automatically discard device-specific
//  resources if the Direct3D device disappears during function
//  invocation, and will recreate the resources the next time it's
//  invoked.
//
HRESULT DemoApp::OnRender()
{
    HRESULT hr;

    hr = CreateDeviceResources();

    if (SUCCEEDED(hr))
    {
        static const WCHAR sc_helloWorld[] = L"Hello, World!";

        // Retrieve the size of the render target.
        D2D1_SIZE_F renderTargetSize = m_pRenderTarget->GetSize();

        m_pRenderTarget->BeginDraw();

        m_pRenderTarget->SetTransform(D2D1::Matrix3x2F::Identity());

        m_pRenderTarget->Clear(D2D1::ColorF(D2D1::ColorF::White));

        m_pRenderTarget->DrawText(
            sc_helloWorld,
            ARRAYSIZE(sc_helloWorld) - 1,
            m_pTextFormat,
            D2D1::RectF(0, 0, renderTargetSize.width, renderTargetSize.height),
            m_pBlackBrush
            );

        hr = m_pRenderTarget->EndDraw();

        if (hr == D2DERR_RECREATE_TARGET)
        {
            hr = S_OK;
            DiscardDeviceResources();
        }
    }

    return hr;
}

需求

需求
程式庫
D2d1.lib
DLL
D2d1.dll

另請參閱

ID2D1RenderTarget