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::Button1Click(TObject *Sender)
{
   double nMax; // Maximum width or height for bitmaps in the list
   double BitmapWidth; // Width of the bitmap
   double BitmapHeight; // Height of the bitmap
   short I;  // Loop Counter
   LEADRasterIO * pRasterIO=NULL;
   LEADRasterProcess* pRasterProc=NULL;
   LEADRaster* pRaster2=NULL ;


   CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL, IID_ILEADRasterIO, (void**)&pRasterIO);
     CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
   CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&pRaster2);

     nMax = 160;
   pRasterIO->Load (pRaster2, AnsiToOLESTR("v:\\images\\24bit.bmp"), 0, 0, 1);
   BitmapWidth = pRaster2->BitmapWidth;
   BitmapHeight = pRaster2->BitmapHeight;
   // Reduce memory requirements, if necessary. Only small bitmaps play smoothly.
   if (BitmapWidth > nMax)
      pRasterProc->Size (pRaster2, nMax, (BitmapHeight * nMax) / BitmapWidth, RESIZE_RESAMPLE);
   else
   {
      if(BitmapHeight > nMax)
         pRasterProc->Size (pRaster2, (BitmapWidth * nMax) / BitmapHeight, nMax, RESIZE_RESAMPLE);
   }
   // Dither to an optimized palette, leaving the last color blank to use
   // for transparency.
   pRasterProc->ColorRes (pRaster2, 8, CRP_IDENTITYPALETTE, CRD_FLOYDSTEINDITHERING, 255);
   // Set an arbitrary transparent color in the last position of the bitmap palette.
   pRaster2->set_BitmapPalette (255, RGB(212, 222, 202));
   // Set the playback values that will apply to all bitmaps in the list.
   pRaster2->BitmapDelay = 10;
   pRaster2->BitmapTop = 0;
   pRaster2->BitmapLeft = 0;
   pRaster2->BitmapEnableTransparency = True;
   pRaster2->BitmapTransparentColor = 16777216 + 255; // Specified by palette index
   pRaster2->BitmapDisposalMethod = ANIMATIONDISPOSAL_RESTOREBACKGROUND;
   // Free the LEADRasterView1 control//s current bitmap list.
   LEADRasterView1->Raster->BitmapList = 0;
   // Populate the bitmap list in the LEADRasterView1 control.
   LEADRasterView1->EnablePaint = False;
   for (I = 0; I<= 36; I ++)
   {
      LEADRasterView1->Raster->InsertBitmapListItem (I, pRaster2->Bitmap);
      // Rotate, using the transparent color as the fill color.
      LEADRasterView1->Raster->BitmapListIndex =I;
      pRasterProc->Rotate (LEADRasterView1->Raster, 1000 * I, (RotateConstants)0, 16777216 + 255);
   }
   LEADRasterView1->EnablePaint = true;
   // Set the animation playback properties
   LEADRasterView1->AnimationBackColor = (TColor)RGB(0, 0, 255);
   LEADRasterView1->AnimationBitsPerPixel = 8;
   LEADRasterView1->AnimationHeight = LEADRasterView1->ScaleHeight;
   LEADRasterView1->AnimationWidth = LEADRasterView1->ScaleWidth;
   LEADRasterView1->AnimationLoop = false;
   for (I = 0; I <= 255; I++)
      LEADRasterView1->AnimationPalette [I] = LEADRasterView1->Raster->get_BitmapPalette (I);

   // Set properties for a scaled animation.
   LEADRasterView1->AutoRepaint = true;
   LEADRasterView1->AutoSetRects = false;
   // Set the image display size to match the LEAD Raster View control.
   LEADRasterView1->SetDstRect (0, 0, LEADRasterView1->ScaleWidth, LEADRasterView1->ScaleHeight);
   LEADRasterView1->SetDstClipRect (0, 0, LEADRasterView1->ScaleWidth, LEADRasterView1->ScaleHeight);
   // Start the animation.
   LEADRasterView1->AnimationEnable = true;
   // Free the Raster2 object//s bitmap list.
   pRaster2->BitmapList = 0;
   pRasterProc-> Release( );
   pRasterIO-> Release( );
   pRaster2 -> Release( );
}