Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

How to Create a Bitmap Brush

To create a bitmap brush, use the ID2D1RenderTarget::CreateBitmapBrush method and specify the bitmap brush properties. Some overloads enable you to specify the brush properties. The following code shows how to create a bitmap brush to fill a square, and a solid black brush to draw the outline of the square. The code produces the output shown in the following screen shot.

Note  Starting with Windows 8, you can use the CreateBitmapBrush method on the ID2D1DeviceContext interface to create a ID2D1BitmapBrush instead of a ID2D1BitmapBrush. ID2D1BitmapBrush adds high-quality scaling modes to the bitmap brush.

Screen shot of a square filled with a plant bitmap

  1. Declare a variable of type ID2D1BitmapBrush.
    
        ID2D1BitmapBrush *m_pBitmapBrush;
    
    
    
  2. Load a bitmap from a resource. For more information, see How to Load a Bitmap from a Resource.
    
    // Create the bitmap to be used by the bitmap brush.
    if (SUCCEEDED(hr))
    {
        hr = LoadResourceBitmap(
            m_pRenderTarget,
            m_pWICFactory,
            L"FERN",
            L"Image",
            &m_pBitmap
            );
    
    
    
  3. Choose the extend modes (D2D1_EXTEND_MODE) and interpolation mode (D2D1_BITMAP_INTERPOLATION_MODE) of the bitmap brush and then call the CreateBitmapBrush method to create a brush, as shown in the following code.
    
    hr = m_pRenderTarget->CreateBitmapBrush(
        m_pBitmap,
        &m_pBitmapBrush
        );
    
    
    

Related topics

Direct2D Reference

 

 

Community Additions

ADD
Show:
© 2015 Microsoft