EN
Dieser Inhalt ist in Ihrer Sprache leider nicht verfügbar. Im Folgenden finden Sie die englische Version.

ID2D1BitmapRenderTarget interface

Renders to an intermediate texture created by the CreateCompatibleRenderTarget method.

When to implement

Custom implementations are not supported.

Members

The ID2D1BitmapRenderTarget interface inherits from ID2D1RenderTarget. ID2D1BitmapRenderTarget also has these types of members:

Methods

The ID2D1BitmapRenderTarget interface has these methods.

MethodDescription
GetBitmap

Retrieves the bitmap for this render target. The returned bitmap can be used for drawing operations.

 

Remarks

An ID2D1BitmapRenderTarget writes to an intermediate texture. It's useful for creating patterns for use with an ID2D1BitmapBrush or caching drawing data that will be used repeatedly.

To write directly to a WIC bitmap instead, use the ID2D1Factory::CreateWicBitmapRenderTarget method. This method returns an ID2D1RenderTarget that writes to the specified WIC bitmap. For an example, see the Save as Image File Sample.

Creating ID2D1BitmapRenderTarget Objects

To create a bitmap render target, call the ID2D1RenderTarget::CreateCompatibleRenderTarget method.

Like other render targets, an ID2D1BitmapRenderTarget is a device-dependent resource and must be recreated when the associated device becomes unavailable. For more information, see the Resources Overview.

Examples

The following example uses the CreateCompatibleRenderTarget method to create an ID2D1BitmapRenderTarget and uses it to draw a grid pattern. The grid pattern is used as the source of an 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;
}


The following code example uses the brush to paint a pattern.


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


Code has been omitted from this example. For the complete code, see the Simple Direct2D Application Sample.

Requirements

Minimum supported client

Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Header

D2d1.h

Library

D2d1.lib

DLL

D2d1.dll

See also

CreateCompatibleRenderTarget
ID2D1Factory::CreateWicBitmapRenderTarget

 

 

Community-Beiträge

HINZUFÜGEN
Anzeigen:
© 2014 Microsoft