Creating a Brush Object

How you create a Brush object depends on the type of brush needed. Because solid brushes are Brush objects, you create a solid brush as follows:

Brush br = Brush.BLACK;

A pattern brush is represented by the Brush object as an integer constant and is created as follows:

Brush br = new Brush(Color.BLACK, BrushStyle.FORWARDDIAGONAL);

The following code fragment demonstrates one way to create a brush based on a bitmap:

Brush bmpBrush = new Brush(new Bitmap("c:\\myBitmap.bmp"));

This example assumes that the bitmap on which you want to base your brush pattern is stored in a file on disk. However, you can also use the Bitmap object’s createBitmap method to define bitmaps at run time, and can use the bitmap you define as the basis for the brush pattern.