Initializing and Freeing DigitalPaint Handles

The LEADTOOLS Digital Paint products use the PAINTHANDLE structure as a working area for the painting functions. This handle must be initialized, by calling L_PntInit, before calling other DigitalPaint functions. L_PntInit creates a valid paint handle. To determine whether a paint handle is valid, call L_PntIsValid. When the paint handle is no longer needed, it should be freed by calling L_PntFree.

As an example, the user may initialize a paint handle at the beginning of a program, saving the paint handle in a global variable. The paint handle is then available for use with any of the DigitalPaint functions, called within the program. At the end of the program, when the paint handle is no longer needed, the paint handle can be freed by calling L_PntFree. This process prevents the user from repeatedly initializing and freeing a paint handle during a program.

The following code sample gives an example of creating and initializing a paint handle.

pPAINTHANDLE pPaint ;

// initiate the Paint toolkit.
if ( SUCCESS != L_PntInit ( &pPaint ) )
{
      return FALSE ;
}

Initializing the PAINTHANDLE sets all internal states (properties, clipping region, transformations…etc.) to their default values.

The following code sample checks the validity of a paint handle and, if valid, frees that paint handle. Freeing the paint handle should be done when the paint handle is no longer needed.

if ( SUCCESS == L_PntIsValid ( pPaint ) )
{
    L_PntFree ( pPaint ) ;
}

Once L_PntFree has been called, the paint handle is no longer valid. L_PntInit must be called again to initialize the paint handle and make it valid.

Once the paint handle is initialized, certain paint information should be set. For more information on setting this paint information, refer to Setting DigitalPaint Properties and Setting General DigitalPaint Information.