InsertBitmapListItem Example for C++ 4.0 and later

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.

float nMax = 160.0f; // Maximum width or height for bitmaps in the list
float BitmapWidth, BitmapHeight; // Width and height of the bitmap
short i; // Loop counter

m_Lead2.Load("c:\\lead\\images\\image1.cmp", 0, 0, 1);
BitmapWidth = m_Lead2.GetBitmapWidth();
BitmapHeight = m_Lead2.GetBitmapHeight();

// Reduce memory requirements, if necessary. Only small bitmaps play smoothly. 
if (BitmapWidth > nMax)
   m_Lead2.Size(nMax, (BitmapHeight * nMax) / BitmapWidth, RESIZE_RESAMPLE);
else if (BitmapHeight > nMax)
   m_Lead2.Size((BitmapWidth * nMax) / BitmapHeight, nMax, RESIZE_RESAMPLE);

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

// Set an arbitrary transparent color in the last position of the bitmap palette.
m_Lead2.SetBitmapPalette(255, RGB(212, 222, 202));

// Set the playback values that will apply to all bitmaps in the list.
m_Lead2.SetBitmapDelay(10);
m_Lead2.SetBitmapTop(0.0f);
m_Lead2.SetBitmapLeft(0.0f);
m_Lead2.SetBitmapEnableTransparency(TRUE);
m_Lead2.SetBitmapTransparentColor(16777216 + 255); // Specified by palette index
m_Lead2.SetBitmapDisposalMethod(ANIMATIONDISPOSAL_RESTOREPREVIOUS);

// Free the LEAD1 control's current bitmap list.
m_Lead1.SetBitmapList(0);

// Populate the bitmap list in the LEAD1 control.
for (i = 0; i <= 36; ++ i)
{
   m_Lead1.InsertBitmapListItem(i, m_Lead2.GetBitmap());

   // Rotate, using the transparent color as the fill color.
   m_Lead1.SetBitmapListIndex(i);
   m_Lead1.Rotate(1000 * i, 0, 16777216 + 255);
}

/* Set the animation playback properties */
m_Lead1.SetAnimationBackColor(RGB(0,0,255));
m_Lead1.SetAnimationBitsPerPixel(8);
m_Lead1.SetAnimationHeight(m_Lead1.GetScaleHeight());
m_Lead1.SetAnimationWidth(m_Lead1.GetScaleWidth());
m_Lead1.SetAnimationLoop(FALSE);
for (i = 0; i < 256; ++ i)
   m_Lead1.SetAnimationPalette(i, m_Lead1.GetBitmapPalette(i));

// Set properties for a scaled animation.
m_Lead1.SetAutoRepaint(TRUE);
m_Lead1.SetAutoSetRects(FALSE);

// Set the image display size to match the LEAD control.
m_Lead1.SetDstRect(0.0f, 0.0f, m_Lead1.GetScaleWidth(), m_Lead1.GetScaleHeight());
m_Lead1.SetDstClipRect(0.0f, 0.0f, m_Lead1.GetScaleWidth(), m_Lead1.GetScaleHeight());

// Start the animation.
m_Lead1.SetAnimationEnable(TRUE);

// Free the LEAD2 control's bitmap.
m_Lead2.SetBitmapList(0);