Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using an animated image with image widget

This topic shows how to create an image widget, load it with a simple animation bitmap, and animate it. The example code shown below is from c_animimagewidget_app. This sample application uses a simple bitmap animation with four frames in one image and embedded in a resource file.

To use an animated image with an image widget, an application needs to do the following:

  • Create an image widget.
  • Load the image with multiple frames from the resource.
  • Set the frame count of the image widget.
  • Set the loaded image to the image widget.
  • Set the extent of the Image widget.
  • Insert the Image widget in the Root container.
  • Start the animation of the widget.

Create an Image widget

After setting up the root container and display canvas, as described in Setting up the root container, create an image widget, as follows:

ERR_TRY( ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_CImageWidget,     
            (void**) &pMe->piw) );

Load the image with multiple frames from the resource

The image widget requires the user to set a fully decoded IImage.

IImage *piImage = NULL;

This example uses a bitmap image that contains 4 frames, which is loaded as follows:

piImage = ISHELL_LoadResImage(pMe->a.m_pIShell, C_ANIMIMAGEWIDGET_APP_RES_FILE,     
                                                              IDB_ANIM_IMAGE);    
ERR_TRY(piImage == NULL);

Set the frame count of the image widget:

IImage_SetFrameCount(piImage, ANIMATION_FRAMES);

Set the loaded image to the image widget:

ERR_TRY(IWidget_SetImage(pMe->piw, piImage));

Set the extent of the image widget:

IWidget_GetPreferredExtent(pMe->piw, &we);    
IWidget_SetExtent(pMe->piw, &we);

Insert the image widget in the root container

The following code inserts the widget in the root container and ensures that it is visible. The insert coordinates in this example are in the middle of the screen.

WidPos.bVisible = TRUE;    
WidPos.x = (pMe->DeviceInfo.cxScreen - we.width) / 2;    
WidPos.y = (pMe->DeviceInfo.cyScreen - we.height) / 2;    
(void) IRootContainer_Insert(pMe->picRoot, pMe->piw, WIDGET_ZNORMAL, &WidPos);

Start animation of the widget:

ERR_TRY(IWidget_SetImageAnimate(pMe->piw, TRUE));