InsertBitmapListItem Example for Visual J++

This example loads an ordinary file and uses it to create and play an animation. It assumes that the LEAD control has already been sized to the aspect ratio of the image.

int nMax = 160;
LEAD2.Load( "c:\\lead\\images\\image1.cmp", (short) 0, (short) 0, (short) 1 );
int nBitmapWidth = (int) LEAD2.getBitmapWidth();
int nBitmapHeight = (int) LEAD2.getBitmapHeight();

// Reduce memory requirements, if necessary. Only small bitmaps play smoothly.
if( nBitmapWidth > nMax )
   LEAD2.Size( nMax, (nBitmapHeight * nMax) / nBitmapWidth, (short) LTOCXU.ResizeConstants.RESIZE_RESAMPLE );
else if( nBitmapHeight > nMax )
   LEAD2.Size( ( nBitmapWidth * nMax) / nBitmapHeight, nMax, (short) LTOCXU.ResizeConstants.RESIZE_RESAMPLE );

// Dither to an optimized palette, leaving the last color blank to use
// for transparency.
LEAD2.ColorRes( (short) 8, (short) LTOCXU.ColorResPaletteConstants.CRP_IDENTITYPALETTE, 
                (short) LTOCXU.ColorResDitherConstants.CRD_FLOYDSTEINDITHERING, 
                (short) 255 );

// Set an arbitrary transparent color in the last position of the bitmap palette.
LEAD2.setBitmapPalette( (short) 255, new Color( 212, 222, 202 ) );

// Set the playback values that will apply to all bitmaps in the list.
LEAD2.setBitmapDelay( 10 );
LEAD2.setBitmapTop( 0 );
LEAD2.setBitmapLeft( 0 );
LEAD2.setBitmapEnableTransparency( true );
LEAD2.setBitmapTransparentColor( new Color( 16777216 + 255 ) );  // Specified by palette index
LEAD2.setBitmapDisposalMethod( (short) LTOCXU.AnimationDisposalConstants.ANIMATIONDISPOSAL_RESTOREBACKGROUND );

// Free the Lead1 control's current bitmap list.
LEAD1.setBitmapList( 0 );

// Populate the bitmap list in the LEAD1 control.
for( short i = 0 ; i < 37 ; i++ )
{
   LEAD1.InsertBitmapListItem( i, LEAD2.getBitmap() );

   // Rotate, using the transparent color as the fill color.
   LEAD1.setBitmapListIndex( i );
   LEAD1.Rotate( 1000 * i, 0, new Color( 16777216 + 255 ) );
}

// Set the animation playback properties
LEAD1.setAnimationBackColor( new Color( 0, 0, 255 ) );
LEAD1.setAnimationBitsPerPixel( (short) 8 );
LEAD1.setAnimationHeight( LEAD1.getScaleHeight() );
LEAD1.setAnimationWidth( LEAD1.getScaleWidth() );
LEAD1.setAnimationLoop( false );
for( short i = 0 ; i < 256 ; i++ )
   LEAD1.setAnimationPalette( i, LEAD1.getBitmapPalette( i ) );

// Set properties for a scaled animation.
LEAD1.setAutoRepaint( true );
LEAD1.setAutoSetRects( false );

// Set the image display size to match the LEAD control.
LEAD1.SetDstRect( 0, 0, LEAD1.getScaleWidth(), LEAD1.getScaleHeight() );
LEAD1.SetDstClipRect( 0, 0, LEAD1.getScaleWidth(), LEAD1.getScaleHeight() );

// Start the animation.
LEAD1.setAnimationEnable( true );

// Free the Lead2 control's bitmap.
LEAD2.setBitmapList( 0 );