CreateBitmap, Size, and Combine example for C++ Builder

This example creates a bitmap for Lead2 (same size and BPS as Lead1) and fills it with green. It resizes the Lead1 bitmap, then uses a loop to do multiple combines with the Lead2 bitmap. It then copies the Lead2 bitmap to Lead1 and redisplays Lead1.

int IntMyWidth, IntMyHeight, IntImageWidth, IntImageHeight, MyOp, MyBPS;
float MyWidth, MyHeight, ImageWidth, ImageHeight, VFactor, HFactor;
int TestWidth, TestHeight, VSpacing, HSpacing;
float SrcL, SrcT, DstT, DstL, DstW, DstH;

Screen->Cursor= crHourGlass;
// Create the Lead2 bitmap. (control must already be on the form).
MyWidth= Lead1->BitmapWidth;
MyHeight= Lead1->BitmapHeight;
MyBPS= Lead1->BitmapBits;
Lead2->CreateBitmap(MyWidth, MyHeight, MyBPS);
Lead2->Fill(RGB(0, 255, 0)); // fill with green
// Resize the Lead1 bitmap
ImageWidth= MyWidth * 0.3;
ImageHeight= MyHeight * 0.3;
Lead1->Size(ImageWidth, ImageHeight, SIZE_RESAMPLE);
// Initialize the variables used for multiple combines.
TestWidth= MyWidth; // Used for horizontal positioning
TestHeight= MyHeight; // Used for vertical positioning
IntMyWidth= MyWidth;  // Green bitmap width
IntMyHeight= MyHeight; // Green bitmap height
IntImageWidth= ImageWidth; // Resized bitmap width
IntImageHeight= ImageHeight; // Resized bitmap height
VFactor= (MyHeight / ImageHeight) + 1; // Number spaces between images
VSpacing= (IntMyHeight % IntImageHeight) / VFactor; // Pixels per space
HFactor= (ClientWidth / ImageWidth) + 1; // Number spaces between images
HSpacing= (IntMyWidth % IntImageWidth) / HFactor; // Pixels per space
SrcL= 0; // Left coordinate of the source rectangle
SrcT= 0; // Top coordinate of the source rectangle
DstW= ImageWidth;  // Width of the destination rectangle
DstH= ImageHeight; // Height of the destination rectangle
MyOp= CB_OP_ADD | CB_DST_0; // Operation flags used when combining images

// Do the loop that does the multiple combines
while(TestHeight > IntImageHeight) // Vertical loop
{
   DstT= IntMyHeight - TestHeight + VSpacing;
   TestHeight= TestHeight - IntImageHeight - VSpacing;
   while (TestWidth > IntImageWidth) //Horizontal loop
   {
      DstL= IntMyWidth - TestWidth + HSpacing;
      TestWidth= TestWidth - IntImageWidth - HSpacing;
      Lead2->Combine(DstL, DstT, DstW, DstH, Lead1->Bitmap, SrcL, SrcT, MyOp);
   }
   TestWidth= IntMyWidth;
}

// Copy the Lead2 bitmap to Lead1
Lead1->Bitmap= Lead2->Bitmap;
Lead2->Bitmap = 0;
//Set the image display size to match the LEAD control
Lead1->SetDstRect(0, 0, Lead1->BitmapWidth, Lead1->BitmapHeight);
Lead1->SetDstClipRect(0, 0, Lead1->BitmapWidth, Lead1->BitmapHeight);
Lead1->ForceRepaint();
// Repaint the image
Screen->Cursor= crDefault;