ID2D1RenderTarget::EndDraw 方法 (d2d1.h)

結束轉譯目標上的繪圖作業,並指出目前的錯誤狀態和相關聯的標記。

語法

HRESULT EndDraw(
  [out, optional] D2D1_TAG *tag1,
  [out, optional] D2D1_TAG *tag2
);

參數

[out, optional] tag1

類型: D2D1_TAG*

當這個方法傳回時,會包含導致錯誤的繪圖作業標記,如果沒有錯誤,則為 0。 這個參數會以未初始化的狀態傳遞。

[out, optional] tag2

類型: D2D1_TAG*

當這個方法傳回時,會包含導致錯誤的繪圖作業標記,如果沒有錯誤,則為 0。 這個參數會以未初始化的狀態傳遞。

傳回值

類型: HRESULT

如果方法成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼,並將 tag1tag2 設定為發生錯誤時作用中的標記。

備註

繪圖作業只能在 BeginDrawEndDraw 呼叫之間發出。

BeginDrawEndDraw 可用來指出 Direct2D 系統正在使用轉譯目標。 呼叫 BeginDraw 時,ID2D1RenderTarget 的不同實作可能會有不同的行為。 ID2D1BitmapRenderTarget 可能會在 BeginDraw/EndDraw 呼叫之間鎖定,DXGI 表面轉譯目標可能會在 BeginDraw 上取得,並在 EndDraw 上釋放,而 ID2D1HwndRenderTarget 可能會在 BeginDraw 開始批處理,例如在 EndDraw 上。

必須先呼叫 BeginDraw 方法,才能呼叫轉譯作業,但狀態設定和狀態擷取作業甚至可以在 BeginDraw EndDraw/ 外部執行。

呼叫 BeginDraw 之後,轉譯目標通常會建置一批轉譯命令,但延遲處理這些命令,直到內部緩衝區已滿、呼叫 Flush 方法,或直到呼叫 EndDraw 為止。 EndDraw 方法會導致任何批次的繪圖作業完成,然後傳回 HRESULT,指出作業成功,並選擇性地傳迴轉譯目標的標記狀態發生錯誤時。 EndDraw 方法一律會成功:即使先前的 EndDraw 導致 HRESULT 失敗,也不應該呼叫兩次。

如果呼叫 EndDraw 而不呼叫 BeginDraw,則會傳回錯誤,指出必須在 EndDraw 之前呼叫 BeginDraw

在轉譯目標上呼叫 BeginDraw 兩次會讓目標進入無法進一步繪製的錯誤狀態,並在呼叫 EndDraw 時傳回適當的 HRESULT 和錯誤資訊。

範例

下列範例會使用 ID2D1HwndRenderTarget 將文字繪製到視窗。

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

規格需求

需求
最低支援的用戶端 適用於 Windows Vista 的 Windows 7、Windows Vista SP2 和平臺更新 [傳統型應用程式 |UWP 應用程式]
最低支援的伺服器 Windows Server 2008 R2、Windows Server 2008 SP2 和 Platform Update for Windows Server 2008 [傳統型應用程式 |UWP 應用程式]
目標平台 Windows
標頭 d2d1.h
程式庫 D2d1.lib
Dll D2d1.dll

另請參閱

ID2D1RenderTarget