InsertBitmapListItem example for C++ Builder

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.

 

void __fastcall TForm1::Button26Click(TObject *Sender)
{
   int nMax;  /* Maximum width or height for bitmaps in the list */
   int BitmapWidth;  /* Width of the bitmap */
   int BitmapHeight;  /* Height of the bitmap */
   int i;         /* Loop Counter */

   nMax = 160;
   Lead2->Load("d:\\ltwin11\\images\\image1.cmp", 0, 0, 1);
   BitmapWidth = Lead2->BitmapWidth;
   BitmapHeight = Lead2->BitmapHeight;
   /* Reduce memory requirements, if( necessary. Only small bitmaps play smoothly. */
   if (BitmapWidth > nMax)
      Lead2->Size(nMax, (int)((BitmapHeight * nMax) / BitmapWidth), SIZE_RESAMPLE);
   else
      if( (BitmapHeight > nMax))
         Lead2->Size((int)((BitmapWidth * nMax) / BitmapHeight), nMax, SIZE_RESAMPLE);

   /* Dither to an optimized palette, leaving the last color blank to use */
   /* for transparency. */
   Lead2->ColorRes(8, CRF_IDENTITYPALETTE, CRF_FLOYDSTEINDITHERING, 255);
   /* Set an arbitrary transparent color in the last position of the bitmap palette. */
   Lead2->BitmapPalette[255] = (TColor)RGB(212, 222, 202);
   /* Set the playback values that will apply to all bitmaps in the list. */
   Lead2->BitmapDelay = 10;
   Lead2->BitmapTop = 0;
   Lead2->BitmapLeft = 0;
   Lead2->BitmapEnableTransparency = True;
   Lead2->BitmapTransparentColor = (TColor)(16777216 + 255); /* Specified by  palette index*/
   Lead2->BitmapDisposalMethod = 2; //PLAYDISPOSE_RESTOREBACKGROUND;
   /* Free the LEAD1 control"s current bitmap list. */
   Lead1->BitmapList = 0;
   /* Populate the bitmap list in the LEAD1 control. */
   for(i= 0;i<=36;i++)
   {
      Lead1->InsertBitmapListItem(i, Lead2->Bitmap);
      /* Rotate, using the transparent color as the fill color. */
      Lead1->BitmapListIndex = i;
      Lead1->Rotate(1000 * i, False, 16777216 + 255);
   }
   /* Set the animation playback properties */
   Lead1->AnimationBackColor = (TColor)RGB(0, 0, 255);
   Lead1->AnimationBitsPerPixel = 8;
   Lead1->AnimationHeight = Lead1->Height;
   Lead1->AnimationWidth = Lead1->Width;
   Lead1->AnimationLoop = False;
   for(i = 0;i<=255;i++)
      Lead1->AnimationPalette[i] = (TColor)Lead1->BitmapPalette[i];
   /* Set properties for a scaled animation. */
   Lead1->AutoRepaint = True;
   Lead1->AutoSetRects = False;
   /* Set the image display size to match the LEAD control. */
   Lead1->SetDstRect(0, 0, Lead1->Width, Lead1->Height);
   Lead1->SetDstClipRect(0, 0, Lead1->Width, Lead1->Height);
   /* Start the animation. */
   Lead1->AnimationEnable = True;
   /* Free the LEAD2 control"s bitmap. */
   Lead2->BitmapList = 0;
}