InsertBitmapListItem Example for C++ 5.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.
ILEADRasterIO *pRasterIO=NULL;
ILEADRasterProcess *pRasterProc=NULL;
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
CoCreateInstance(CLSID_LEADRasterIO, NULL, CLSCTX_ALL,
IID_ILEADRasterIO, (void**)&pRasterIO);
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL,
IID_ILEADRasterProcess, (void**)&pRasterProc);
pRasterIO->Load(m_LEADRasterView2.GetRaster(),
"d:\\lead14\\dist\\images\\image1.cmp",
0, 0, 1);
BitmapWidth = m_LEADRasterView2.GetRaster().GetBitmapWidth();
BitmapHeight = m_LEADRasterView2.GetRaster().GetBitmapHeight();
// Reduce memory requirements, if necessary. Only small bitmaps play smoothly.
if(BitmapWidth > nMax)
pRasterProc->Size(m_LEADRasterView2.GetRaster(),
nMax, (BitmapHeight * nMax) / BitmapWidth,
RESIZE_RESAMPLE);
else if(BitmapHeight > nMax)
pRasterProc->Size(m_LEADRasterView2.GetRaster(),
(BitmapWidth * nMax) / BitmapHeight, nMax,
RESIZE_RESAMPLE);
// Dither to an optimized palette, leaving the last color blank to use
// for transparency.
pRasterProc->ColorRes(m_LEADRasterView2.GetRaster(),
8, CRP_IDENTITYPALETTE,
CRD_FLOYDSTEINDITHERING, 255);
// Set an arbitrary transparent color in the last position of the bitmap palette.
m_LEADRasterView2.GetRaster().SetBitmapPalette(255, RGB(212, 222, 202));
// Set the playback values that will apply to all bitmaps in the list.
m_LEADRasterView2.GetRaster().SetBitmapDelay(10);
m_LEADRasterView2.GetRaster().SetBitmapTop(0.0f);
m_LEADRasterView2.GetRaster().SetBitmapLeft(0.0f);
m_LEADRasterView2.GetRaster().SetBitmapEnableTransparency(TRUE);
m_LEADRasterView2.GetRaster().SetBitmapTransparentColor(16777216 + 255); // Specified by palette index
m_LEADRasterView2.GetRaster().SetBitmapDisposalMethod(ANIMATIONDISPOSAL_RESTOREPREVIOUS);
// Free the LEAD1 control's current bitmap list.
m_LEADRasterView1.GetRaster().SetBitmapList(0);
// Populate the bitmap list in the LEAD1 control.
for (i = 0; i <= 36; ++ i)
{
m_LEADRasterView1.GetRaster().InsertBitmapListItem(i, m_LEADRasterView2.GetRaster().GetBitmap());
// Rotate, using the transparent color as the fill color.
m_LEADRasterView1.GetRaster().SetBitmapListIndex(i);
pRasterProc->Rotate(m_LEADRasterView1.GetRaster(),
1000 * i, (RotateConstants)0,
16777216 + 255);
}
/* Set the animation playback properties */
m_LEADRasterView1.SetAnimationBackColor(RGB(0,0,255));
m_LEADRasterView1.SetAnimationBitsPerPixel(8);
m_LEADRasterView1.SetAnimationHeight(m_LEADRasterView1.GetScaleHeight());
m_LEADRasterView1.SetAnimationWidth(m_LEADRasterView1.GetScaleWidth());
m_LEADRasterView1.SetAnimationLoop(FALSE);
for (i = 0; i < 256; ++ i)
m_LEADRasterView1.SetAnimationPalette(i, m_LEADRasterView1.GetRaster().GetBitmapPalette(i));
// Set properties for a scaled animation.
m_LEADRasterView1.SetAutoRepaint(TRUE);
m_LEADRasterView1.SetAutoSetRects(FALSE);
// Set the image display size to match the LEAD control.
m_LEADRasterView1.SetDstRect(0.0f, 0.0f, m_LEADRasterView1.GetScaleWidth(), m_LEADRasterView1.GetScaleHeight());
m_LEADRasterView1.SetDstClipRect(0.0f, 0.0f, m_LEADRasterView1.GetScaleWidth(), m_LEADRasterView1.GetScaleHeight());
// Start the animation.
m_LEADRasterView1.SetAnimationEnable(TRUE);
// Free the LEAD2 control's bitmap.
m_LEADRasterView2.GetRaster().SetBitmapList(0);
pRasterIO->Release();
pRasterProc->Release();