Minimizing Flicker with Double Buffering

Double buffering is used to reduce flickering when painting windows. In many cases, double buffering is entirely unnecessary, but there are some instances where it can improve the appearance of your application.

For example, there are certain situations when using annotations that "flickering" is very difficult to avoid. One such situation occurs when zooming in very quickly on an annotation. To see this, perform the following steps:

1.

Run the main C API annotation demo (annot32.exe)

2.

Load an image

3.

Draw a button annotation

4.

In the View menu, disable double buffering

5.

Hold the "+" key to zoom in very quickly

Note that you can very clearly see the image being painted, and then the annotation over the image. For a fraction of a second, you can see the image under the annotation.

Now enable the double buffering option, and begin zooming. Notice how there is no flickering.

You can very easily add double buffering to your applications by using the following functions.

L_DoubleBufferBegin

L_DoubleBufferCreateHandle

L_DoubleBufferDestroyHandle

L_DoubleBufferEnable

L_DoubleBufferEnd

To use double buffering, first you must create a double buffer handle using L_DoubleBufferCreateHandle. The double buffer handle is an argument for all of the double buffering functions.

Next you must decide which paint operations will be double buffered. All such paint operations must be wrapped in L_DoubleBufferBegin and L_DoubleBufferEnd calls.

The L_DoubleBufferBegin call returns a memory hDC. All subsequent paint operations should use this hDC for painting. To render the contents of the memory hDC, call L_DoubleBufferEnd.

The L_DoubleBufferBegin and L_DoubleBufferEnd calls intelligently manage an internal memory hDC. The memory hDC is only reallocated when necessary.

At any time in your application, you can easily enable/disable the double buffering by calling L_DoubleBufferEnable with appropriate arguments. When the double buffering is disabled, all wrapped paint calls paint directly to the screen. When double buffering is enabled, paints are triggered only by calls to L_DoubleBufferEnd.

When you are finished double buffering, call L_DoubleBufferDestroyHandle to free the internally allocated resources.

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help