Using a Bitmap-Patterned Brush

If the brush style is set to a patterned brush, then a bitmap can be used for filling shapes. The following example code illustrate how this is done. The bitmap is tiled around the given origin - the top left of the window is the default - and clipped to the given shape. The second bitmapped brush example shows the effect of moving the origin.

Using a bitmap patterned brush, with the default origin

  1. Load the bitmap file in the standard way.

  2. Use the bitmap as the graphics context’s brush pattern.

  3. Set the brush style to TBrushStyle::EPatternedBrush.

  4. Discard the brush pattern using DiscardBrushPattern().

  5. Destroy the bitmap.

With no brush origin set, the tiling pattern starts at the top left corner of the window.

CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
// set brush pattern and style to use the bitmap
// draw shape filled with bitmap pattern

Using a bitmap patterned brush, with a set origin

You can set the brush origin using SetBrushOrigin(), and tile the bitmap around this point.

The example code is exactly the same as that in previous bitmapped brush example, except that the following line is added before the rectangle is drawn:

TPoint pos(100,100);

For using bitmaps, see BitGDI Component.

Related concepts