Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Implementing Animation using CAknBitmapAnimation

From Wiki
Jump to: navigation, search

The example code snippets show how to create a simple animation using the Symbian C++ class CAknBitmapAnimation. This class provides an interface to an animation DLL, so we only need to provide it with some images and attribute data.

Article Metadata
Created: vasant21 (07 May 2007)
Last edited: hamishwillee (25 Jan 2012)

The important part of the animation example are the Frames (Images) which complete the animation sequence.


What is required

Three essential resources are needed to construct an animation

  1. Bitmap Animation Data.
  2. Array of bitmap frames.
  3. Bitmap Images.

Bitmap Animation Data

It is the Resource defining the animation to be used by CAknBitmapAnimation.

	RESOURCE BMPANIM_DATA r_animation_data
// Represents delay between frames
frameinterval = 400;
// There are three play mode available
1) EAknBitmapAnimationPlayModePlay :
play once
2) EAknBitmapAnimationPlayModeCycle :
repeat from the first frame to the last.
3) EAknBitmapAnimationPlayModeBounce :
play the first frame to the last and then back down to
the first, repeatedly. */

playmode = EAknBitmapAnimationPlayModeBounce;
// Represents Flashing is On or Off.
flash = 0;
// The .mbm file containing the animation frame.
// Reference to the ARRAY resource of BMPANIM_FRAME definitions.
frames = r_animation_array ;

The ANIMATION_BMPFILE_NAME is the .mbm (Multi-Bitmap file) and creating .mbm file is the preferred way of using bitmaps and accessing the bitmaps runtime.

Hence you need to specifiy the .mbm file name and the bitmaps to be included, this file is generated by the compiler.

Below is the code in .mmp file for generating .mbm file. Specify all the images to be used in the animation. This files are by default stored at \system\apps\applicationname folder\

START BITMAP Animation.mbm
SOURCE C12 DisplayImageFrame1.bmp
SOURCE C12 DisplayImageFrame2.bmp
SOURCE C12 DisplayImageFrame3.bmp
SOURCE C12 DisplayTextFrame.bmp

The IDs are generated into the mbg file. The bitmaps can be accessed from the mbm file with this ID number. Each ID number is constructed automatically and is in the following format: EMbm<MBM file name><bitmap file name>, for example, EMbmMygameImage1.

Array of bitmap frames.

This is the Array of BMPANIM_FRAME elements that will be used by BMPANIM_DATA and finally CAknBitmapAnimation.

RESOURCE ARRAY r_animation_array
items =
// time  : represents time that frame is displayed for.
// bmpid : ID from of the desired bitmap from the .mbm file for this frame.
BMPANIM_FRAME { time = 200; bmpid = EMbmAnimationDisplayimageframe1;},
BMPANIM_FRAME { time = 200; bmpid = EMbmAnimationDisplayimageframe2;},
BMPANIM_FRAME { time = 200; bmpid = EMbmAnimationDisplayimageframe3;},
BMPANIM_FRAME { time = 200; bmpid = EMbmAnimationDisplayimageframe1;},
BMPANIM_FRAME { time = 200; bmpid = EMbmAnimationDisplayimageframe2;},
BMPANIM_FRAME { time = 200; bmpid = EMbmAnimationDisplayimageframe3;},
BMPANIM_FRAME { time = 1000; bmpid = EMbmAnimationDisplaytextframe; }

Bitmap Images

This bitmaps are the images (frames) that in sequence creates the animation.

Using the prepared Resources

Once all the required resources are prepare, we are ready for preparing animation control.

In the Header file include

#include <aknbitmapanimation.h> 
//Forward Declaration
class CAknBitmapAnimation;

Inside the Container Class

CAknBitmapAnimation* iAnimation;

And do not forget to include

 #include <BARSREAD.h>

This header file is required by TResourceReader

Now in the cpp file

// instantiate CAknBitmapAnimation
iAnimation = CAknBitmapAnimation::NewL();
// creating a TResourceReader object for reading the resource.
TResourceReader reader;
// map resource to resource reader
iCoeEnv->CreateResourceReaderLC(reader, R_ANIMATION_DATA);
// provide animation control with animation data
// animation control needs a window
// starts the animation.
// Pop and Destroy the resource reader

Canceling Animation


bmconv tool

Bitmaps provide the pixel patterns used by pictures, icons and masks, sprites and brush styles for filling areas of the display. To optimize bitmap performance, Symbian OS uses files containing multiple bitmaps in its own highly compressed format. A tool is provided (bmconv.exe) with the S60 SDK that takes one or more Windows bitmap (.bmp) files as input and generates a single Symbian OS multi-bitmap file (.mbm), optimized for efficient runtime loading.

The bmconv tool also generates a header file (.mbg) with symbolic definitions (identifiers) for each bitmap in the file. This generated header file is placed in the \epoc32\include folder of the SDK. It is intended for inclusion (#include) in your C++ code to allow you to reference any of the individual bitmaps as required.

Two types of .mbm files are possible, file store bitmap files that are loaded into RAM and ROM image bitmap files that do not use any RAM when being accessed—only system developers normally create ROM-based .mbm files.

During the conversion process it is possible to specify the number of bits per pixel for the converted bitmaps and whether they should be color or grayscale. The program can also split Symbian OS multi-bitmap (.mbm) files back into component bitmap files in Windows bitmap (.bmp) format.

You do not always have to use the bmconv tool directly to produce bitmap files that are dedicated to a particular application. Building the required bitmaps can be performed as part of the standard abld project building process. A list of .bmp files can be specified in the project definition (.mmp) file. The above example shows statements in the project definition (.mmp) file using START BITMAP syntax.

This page was last modified on 25 January 2012, at 00:55.
47 page views in the last 30 days.