The LEADTOOLS LRasterPaint class provides the following functions for filling an area:
LRasterPaint::FillColorReplace
These functions require:
an optional windows device context.
the necessary information used to control the filling action.
These functions will fill areas based on the current fill properties. To determine the current fill properties, call LRasterPaint::GetProperty. To set or change the current fill properties, call LRasterPaint::SetProperty. For more information on the fill properties, refer to the PAINTFILLstructure.
The filling functions use different methods to fill an area. The LRasterPaint::FillSurface function fills an area, starting at a specified point and continuing in all directions, that contains a specified color, falling within some tolerance range. The upper and lower tolerances are set in the PAINTFILL structure. The LRasterPaint::FillBorder function fills an area, starting at a specified point and continuing in all directions, until it finds a specified color, falling within some tolerance range. The LRasterPaint::FillColorReplace will replace every pixel using the current fill properties.
Any transformation information should be set, using the LRasterPaint::SetTransformation function before calling any fill or other painting function. To get the current transformation information, call LRasterPaint::GetTransformation.
For selecting a color from a specific point, call LRasterPaint::PickColor.
The following example sets the device context boundaries, sets the fill properties, sets the DigitalPaint metrics properties and then performs a color replacement. It assumes the paint handle has been initialized, and the window handle and lead bitmap handle are valid:
HDC hDC ;
PAINTFILL fill ;
RECT rcDCExtents ;
/* Get device context to draw on */
hDC = GetDC ( hWnd ) ;
/* Get the destination DC dimensions */
GetClientRect ( hWnd, &rcDCExtents ) ;
/* Set the toolkit user DC extents */
// Assume Paint was constructed from LRasterPaint class
Paint.SetDCExtents ( &rcDCExtents ) ;
/* Set the required fill properties */
fill.nSize = sizeof ( PAINTFILL ) ;
fill.dwMask = PFF_STYLE ;
fill.nStyle = PAINT_FILL_STYLE_GRADIENT ;
/* Set the new fill properties */
Paint.SetProperty ( PAINT_GROUP_FILL, &fill ) ;
/*Select the bitmap into the paint class object*/
Paint.SetMetrics ( NULL, &hLeadBitmap, NULL ) ;
/* Fill the target area in the DC (hDC) and the currently selected bitmap*/
Paint.FillColorReplace ( hDC, RGB ( 255, 0, 0 ) ) ;
/* Release the device context */
ReleaseDC ( hWnd, hDC ) ;
This example uses the function LRasterPaint::SetDCExtents. This function is essential in filling the desired area. The user should define the boundaries of the DC supplied to the fill function. The supplied dimensions will be in pixels. To get the DC boundaries previously set, call the LRasterPaint::GetDCExtents function.