InsertBitmapListItem example for Delphi
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.
procedure TForm1.Button1Click(Sender: TObject);
var
nMax: integer; { Maximum width or height for bitmaps in the list}
BitmapWidth: integer; { Width of the bitmap }
BitmapHeight: integer; { Height of the bitmap }
i: Integer; { Loop Counter }
begin
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) then
Lead2.Size(nMax, Round((BitmapHeight * nMax) / BitmapWidth), SIZE_RESAMPLE)
else
if (BitmapHeight > nMax) then
Lead2.Size(Round((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] := 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 := 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 To 36 do
begin
Lead1.InsertBitmapListItem(i, Lead2.Bitmap);
{ Rotate, using the transparent color as the fill color. }
Lead1.BitmapListIndex := i;
Lead1.Rotate(1000 * i, False, 16777216 + 255);
end;
{ Set the animation playback properties }
Lead1.AnimationBackColor := RGB(0, 0, 255);
Lead1.AnimationBitsPerPixel := 8;
Lead1.AnimationHeight := Lead1.Height;
Lead1.AnimationWidth := Lead1.Width;
Lead1.AnimationLoop := False;
for i := 0 to 255 do
Lead1.AnimationPalette[i] := 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;
end;