If you are using the LAnimationWindow (or derived) class, the class object will perform all of the processing required to implement animation for you.
Alternatively, 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:
Create and load a bitmap list using LFile::LoadBitmapList.
Use LBitmapBase::Create to create a target bitmap that is the size of the images in the bitmap list.
Use LPlayBack::Create to create an animation playback that references bitmap list and the target bitmap.
In a loop that processes each bitmap in the list, do the following:
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.
Another way to load and play animated files is by following the steps below:
Create new class derived from LAnimationWindow and override the methods below and from each overridden method call the base class method:
Create and load a bitmap list using LAnimationWindow::Load through an instance of the new derived class above.
Call the LAnimationWindow::PreProcessing function through the instance you created for the new derived class above.
Call the LAnimationWindow::PlayProcessing function through the instance you created for the new derived class above. You can specify whether the playback should be continuous or not through this function parameters.
The animation should be started by now, so if the playback was continuous and you like to stop it you can call the LAnimationWindow::PostProcessing function through the instance you created for the new derived class above.
This way you don't need a loop to call the LAnimationWindow::PlayProcessing function inside it, it will internally create a loop until the playback is finished or the user canceled it through a call to LAnimationWindow::PostProcessing function.
The fastest way to play the animation file while loading it is by calling LAnimationWindow::PlayWhileLoad function after a previous call to LAnimationWindow::Load function, which will internally add each frame of the loaded animation file into the bitmap list and created a loop to go through these frames and play them.
Before you load an animated GIF file, you can use the LFile::GetInfo 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 LFile::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 LFile::SaveList, 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 for supporting functions show how to implement various features. Refer to the following function descriptions:
|Function||What the Example Shows|
|LPlayBack::Process||This example loads a bitmap list from an animated GIF file. It then plays the animation, using the current bitmap as the target.|
|LPlayBack::Append||This example plays an animated GIF file as it loads the file. The example includes both the calling function and the LFile::LoadFileCallBack function, which displays the image.|
|LBitmapList::Create||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.|
|LBitmapList::GetItem||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.|
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.
You can also use the high-level class LAnimationWindow to implement animation. This class creates a window and does all of the processing required to implement animation for you.
Medical Web Viewer .NET
.NET, Java, Android, and iOS/macOS Assemblies
C API/C++ Class Libraries