Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ID2D1DeviceContext::CreateImageBrush method

Creates an image brush. The input image can be any type of image, including a bitmap, effect, or a command list.

Syntax


HRESULT CreateImageBrush(
  [in]                 ID2D1Image                  *image ,
  [in]           const D2D1_IMAGE_BRUSH_PROPERTIES *imageBrushProperties,
  [in, optional] const D2D1_BRUSH_PROPERTIES       *brushProperties,
  [out]                ID2D1ImageBrush             **imageBrush
);

Parameters

image [in]

Type: ID2D1Image*

The image to be used as a source for the image brush.

imageBrushProperties [in]

Type: const D2D1_IMAGE_BRUSH_PROPERTIES*

The properties specific to an image brush.

brushProperties [in, optional]

Type: const D2D1_BRUSH_PROPERTIES*

Properties common to all brushes.

imageBrush [out]

Type: ID2D1ImageBrush**

When this method returns, contains the address of a pointer to the input rectangles.

Return value

Type: HRESULT

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

HRESULTDescription
S_OKNo error occurred.
E_OUTOFMEMORYDirect2D could not allocate sufficient memory to complete the call.
E_INVALIDARGAn invalid value was passed to the method.

 

Remarks

The image brush can be used to fill an arbitrary geometry, an opacity mask or text.

This sample illustrates drawing a rectangle with an image brush.


HRESULT
CreatePatternBrush(
     __in ID2D1DeviceContext *pDeviceContext,
     __deref_out ID2D1ImageBrush **ppImageBrush
     )
{
    HRESULT hr = S_OK;
    ID2D1Image *pOldTarget = NULL;
    pDeviceContext->GetTarget(&pOldTarget);

    ID2D1CommandList *pCommandList = NULL;
    hr = pDeviceContext->CreateCommandList(&pCommandList);
     
    if (SUCCEEDED(hr))
    {   
        pDeviceContext->SetTarget(pCommandList);
        hr = RenderPatternToCommandList(pDeviceContext);
    }

    pDeviceContext->SetTarget(pOldTarget);

    ID2D1ImageBrush *pImageBrush = NULL;

    if (SUCCEEDED(hr))
    {        
         hr = pDeviceContext->CreateImageBrush(
            pCommandList,
            D2D1::ImageBrushProperties(
                D2D1::RectF(198, 298, 370, 470),
                D2D1_EXTEND_MODE_WRAP,
                D2D1_EXTEND_MODE_WRAP,
                D2D1_INTERPOLATION_MODE_LINEAR
                ),
            &pImageBrush
            );
    }
    
    // Fill a rectangle with the image brush.
    if (SUCCEEDED(hr))
    {
        pDeviceContext->FillRectangle(
            D2D1::RectF(0, 0, 100, 100), pImageBrush);
    }

    SafeRelease(&pImageBrush);
    SafeRelease(&pCommandList);
    SafeRelease(&pOldTarget);
    return hr;
}

Requirements

Minimum supported client

Windows 8 and Platform Update for Windows 7 [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2012 and Platform Update for Windows Server 2008 R2 [desktop apps | Windows Store apps]

Minimum supported phone

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

Header

D2d1_1.h

DLL

D2d1.dll

See also

ID2D1DeviceContext
ID2D1RenderTarget::FillGeometry
ID2D1RenderTarget::DrawGeometry
ID2D1DeviceContext::CreateCommandList
ID2D1DeviceContext::CreateEffect
D2D1_IMAGE_BRUSH_PROPERTIES
D2D1_BRUSH_PROPERTIES

 

 

Show:
© 2017 Microsoft