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.
Var
sRet: Smallint;
nMax: Double; // Maximum width or height for bitmaps in the list
BitmapWidth: Double; // Width of the bitmap
BitmapHeight: Double; // Height of the bitmap
I: Longint; // Loop Counter
RasterIO: LEADRasterIO;
RasterProc: LEADRasterProcess;
Raster2: LEADRaster;
begin
RasterIO:= CreateComObject (CLASS_LEADRasterIO) as LEADRasterIO;
RasterProc:= CreateComObject (CLASS_LEADRasterProcess ) as LEADRasterProcess;
Raster2:= CreateComObject (CLASS_LEADRaster) as LEADRaster;
nMax := 160;
RasterIO.Load (Raster2, 'v:\images\24bit.bmp', 0, 0, 1);
BitmapWidth := Raster2.BitmapWidth;
BitmapHeight := Raster2.BitmapHeight;
// Reduce memory requirements, if necessary. Only small bitmaps play smoothly.
if (BitmapWidth > nMax) then
RasterProc.Size (Raster2, nMax, (BitmapHeight * nMax) / BitmapWidth, RESIZE_RESAMPLE)
else
begin
if(BitmapHeight > nMax) then
RasterProc.Size (Raster2, (BitmapWidth * nMax) / BitmapHeight, nMax, RESIZE_RESAMPLE);
end;
// Dither to an optimized palette, leaving the last color blank to use
// for transparency.
RasterProc.ColorRes (Raster2, 8, CRP_IDENTITYPALETTE, CRD_FLOYDSTEINDITHERING, 255);
// Set an arbitrary transparent color in the last position of the bitmap palette.
Raster2.BitmapPalette [255] := RGB(212, 222, 202);
// Set the playback values that will apply to all bitmaps in the list.
Raster2.BitmapDelay := 10;
Raster2.BitmapTop := 0;
Raster2.BitmapLeft := 0;
Raster2.BitmapEnableTransparency := True;
Raster2.BitmapTransparentColor := 16777216 + 255; // Specified by palette index
Raster2.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 to 36 do
begin
LEADRasterView1.Raster.InsertBitmapListItem (I, Raster2.Bitmap);
// Rotate, using the transparent color as the fill color.
LEADRasterView1.Raster.BitmapListIndex := I;
RasterProc.Rotate (LEADRasterView1.Raster, 1000 * I, 0, 16777216 + 255);
end;
LEADRasterView1.EnablePaint := True;
// Set the animation playback properties
LEADRasterView1.AnimationBackColor := RGB(0, 0, 255);
LEADRasterView1.AnimationBitsPerPixel := 8;
LEADRasterView1.AnimationHeight := LEADRasterView1.ScaleHeight;
LEADRasterView1.AnimationWidth := LEADRasterView1.ScaleWidth;
LEADRasterView1.AnimationLoop := False;
for I := 0 to 255 do
LEADRasterView1.AnimationPalette [I] := LEADRasterView1.Raster.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, sRet);
LEADRasterView1.SetDstClipRect (0, 0, LEADRasterView1.ScaleWidth, LEADRasterView1.ScaleHeight, sRet);
// Start the animation.
LEADRasterView1.AnimationEnable := True;
// Free the Raster2 object//s bitmap list.
Raster2.BitmapList := 0
end;