ID2D1BitmapRenderTarget::GetBitmap 方法 (d2d1.h)

擷取這個轉譯目標的點陣圖。 傳回的點陣圖可用於繪圖作業。

語法

HRESULT GetBitmap(
  [out] ID2D1Bitmap **bitmap
);

參數

[out] bitmap

類型: ID2D1Bitmap**

當這個方法傳回時,會包含這個轉譯目標之位圖指標的位址。 此點陣圖可用於繪圖作業。

傳回值

類型: HRESULT

如果此方法成功,則會傳回 S_OK。 否則,它會傳回 HRESULT 錯誤碼。

備註

GetBitmap 取得之 ID2D1Bitmap 的 DPI 將會是建立轉譯目標時 ID2D1BitmapRenderTarget 的 DPI。 呼叫 SetDpi 變更 ID2D1BitmapRenderTarget 的 DPI 不會影響位圖的 DPI,即使 GetBitmap 之前呼叫 SetDpi 也一樣。 使用 SetDpi 來變更 ID2D1BitmapRenderTarget 的 DPI 會影響內容轉譯到位圖的方式:它不會影響 GetBitmap 所擷取之位圖的 DPI。

範例

下列範例使用 CreateCompatibleRenderTarget 方法來建立 ID2D1BitmapRenderTarget, 並使用它繪製網格線模式。 網格線模式會用來作為 ID2D1BitmapBrush的來源。

HRESULT DemoApp::CreateGridPatternBrush(
    ID2D1RenderTarget *pRenderTarget,
    ID2D1BitmapBrush **ppBitmapBrush
    )
{
    // Create a compatible render target.
    ID2D1BitmapRenderTarget *pCompatibleRenderTarget = NULL;
    HRESULT hr = pRenderTarget->CreateCompatibleRenderTarget(
        D2D1::SizeF(10.0f, 10.0f),
        &pCompatibleRenderTarget
        );
    if (SUCCEEDED(hr))
    {
        // Draw a pattern.
        ID2D1SolidColorBrush *pGridBrush = NULL;
        hr = pCompatibleRenderTarget->CreateSolidColorBrush(
            D2D1::ColorF(D2D1::ColorF(0.93f, 0.94f, 0.96f, 1.0f)),
            &pGridBrush
            );
        if (SUCCEEDED(hr))
        {
            pCompatibleRenderTarget->BeginDraw();
            pCompatibleRenderTarget->FillRectangle(D2D1::RectF(0.0f, 0.0f, 10.0f, 1.0f), pGridBrush);
            pCompatibleRenderTarget->FillRectangle(D2D1::RectF(0.0f, 0.1f, 1.0f, 10.0f), pGridBrush);
            pCompatibleRenderTarget->EndDraw();

            // Retrieve the bitmap from the render target.
            ID2D1Bitmap *pGridBitmap = NULL;
            hr = pCompatibleRenderTarget->GetBitmap(&pGridBitmap);
            if (SUCCEEDED(hr))
            {
                // Choose the tiling mode for the bitmap brush.
                D2D1_BITMAP_BRUSH_PROPERTIES brushProperties =
                    D2D1::BitmapBrushProperties(D2D1_EXTEND_MODE_WRAP, D2D1_EXTEND_MODE_WRAP);

                // Create the bitmap brush.
                hr = m_pRenderTarget->CreateBitmapBrush(pGridBitmap, brushProperties, ppBitmapBrush);

                pGridBitmap->Release();
            }

            pGridBrush->Release();
        }

        pCompatibleRenderTarget->Release();
    }

    return hr;
}

下列程式代碼範例會使用筆刷繪製圖樣。

// Paint a grid background.
m_pRenderTarget->FillRectangle(
    D2D1::RectF(0.0f, 0.0f, renderTargetSize.width, renderTargetSize.height),
    m_pGridPatternBitmapBrush
    );

此範例已省略程序代碼。

規格需求

需求
最低支援的用戶端 適用於 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

另請參閱

ID2D1BitmapRenderTarget