Implementing Animation

To load and play an animated GIF file, you can load a list of bitmaps from the file, then play the list to a target bitmap in a loop that displays each change in the target bitmap. You can also create an animation sequence from scratch and save the bitmaps to create an animated GIF file.

The following is an outline of possible steps:

1.

Create and load a bitmap list using L_LoadBitmapList.

2.

Use L_CreateBitmap to create a target bitmap that is the size of the images in the bitmap list.

3.

Use L_CreatePlayback to create an animation playback that references bitmap list and the target bitmap.

4.

In a loop that processes each bitmap in the list, do the following:

a.

Use L_ProcessPlayback to process the current state and get the next state of the playback.

b.

Use L_GetPlaybackUpdateRect to get the update rectangle (the portion of the target bitmap that has changed).

c.

Use L_PaintDC to paint the changed portion of the bitmap. To paint only the changed portion, use the update rectangle as the source clipping rectangle.

The playback loop can have a number of states, and you should only paint the changes in an appropriate state (for example, when the next state is PLAYSTATE_POSTRENDER). For a list of possible states, refer to Animation Playback States.

The DisposalMethod field in the BITMAPHANDLE for the target bitmap determines what happens to the bitmap in the playback loop after rendering and after any wait state, when the next state is PLAYSTATE_POSTDISPOSE. The options are as follows: keep the image as it is, restore the background, or restore the previous image. (Restoring the background is a common option for animation.)

The playback loop goes continuously through the list of bitmaps. If you want to stop at the end of the list, you can exit the loop when the next state is PLAYSTATE_END.

Animated GIF Files

Before you load an animated GIF file, you can use the L_FileInfo function to get the file's global animation information, which is updated in the following FILEINFO fields: Flags, GlobalLoop, GlobalWidth, GlobalHeight, GlobalBackground, and GlobalPalette. You can use these values in the animation playback.

When you load an animated GIF file, using L_LoadBitmapList, the following animation fields in each BITMAPHANDLE are updated with information from the file: Left, Top, Delay, Background, Transparency, and DisposalMethod. These fields are used in the animation playback.

When you save an animated GIF file, using L_SaveBitmapList, these same BITMAPHANDLE fields are saved in the file. In addition, if you want to save the global animation information, you can use the SAVEFILEOPTION structure to set the following fields: Flags, GlobalLoop, GlobalWidth, GlobalHeight, GlobalBackground, and GlobalPalette. Notice that the field names are the same as in the FILEINFO structure (although the values of the Flags field are different).

Code Examples

Code examples for supporting functions show how to implement various features. Refer to the following function descriptions:

Function

What the Example Shows

L_ProcessPlayback

This example loads a bitmap list from an animated GIF file. It then plays the animation, using the current bitmap as the target.

L_AppendPlayback

This example plays an animated GIF file as it loads the file. The example includes both the calling function and the FILEREADCALLBACK function, which displays the image.

L_CreateBitmapList

This example creates a bitmap list from the current bitmap, rotating each copy by 10 degrees. It defines the rotation fill color as a transparent color, and assigns an animation background color. It then plays the animation, using the current bitmap as the target.

L_GetBitmapListItem

This example changes the hue of bitmaps in a list, then updates the paint palette and the target bitmap's palette for animation playback. When changing the hue, it preserves the transparent color in the last palette entry.

Related Functions

For a summary of the functions for creating and managing a bitmap list, refer to Creating and Maintaining Lists of Images.

For a summary of the animation playback functions, refer to Playing Animated Images.

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