ID2D1BitmapRenderTarget 介面 (d2d1.h)

轉譯為 CreateCompatibleRenderTarget 方法所建立的中繼紋理。

繼承

ID2D1BitmapRenderTarget 介面繼承自 ID2D1RenderTargetID2D1BitmapRenderTarget 也有下列類型的成員:

方法

ID2D1BitmapRenderTarget 介面具有這些方法。

 
ID2D1BitmapRenderTarget::GetBitmap

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

備註

ID2D1BitmapRenderTarget 會寫入中繼紋理。 建立與 ID2D1BitmapBrush 搭配使用的模式,或快取將重複使用的繪圖數據很有用。

若要改為直接寫入 WIC 位圖,請使用 ID2D1Factory::CreateWicBitmapRenderTarget 方法。 這個方法會傳回 ID2D1RenderTarget,此ID2D1RenderTarget 會寫入指定的WIC位圖。

建立ID2D1BitmapRenderTarget物件

若要建立位圖轉譯目標,請呼叫 ID2D1RenderTarget::CreateCompatibleRenderTarget 方法。

就像其他轉譯目標一 樣,ID2D1BitmapRenderTarget 是裝置相依的資源,而且必須在相關聯的裝置變成無法使用時重新建立。 如需詳細資訊,請參閱 資源概觀

範例

下列範例使用 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

另請參閱

CreateCompatibleRenderTarget

ID2D1Factory::CreateWicBitmapRenderTarget

ID2D1RenderTarget