Create Bitmap, Size, and Combine example for C++ Builder
This example creates a bitmap for Raster2 (same size and BPS as LEADRasterView1.Raster) and fills it with green. It resizes the LEADRasterView1.Raster bitmap, and then uses a loop to do multiple combines with the Raster2 bitmap. It then copies the Raster2 bitmap to LEADRasterView1 and redisplays LEADRasterView1.
float DstT;
float DstL;
float SrcL;
float SrcT;
float DstW;
float DstH;
float MyWidth;
float MyHeight;
int MyBPS;
int ImageWidth;
int ImageHeight;
int TestWidth;
int TestHeight;
int VFactor;
int VSpacing;
int HFactor;
int HSpacing;
LEADRaster* pRaster2;
CombineConstants MyOP;
LEADRasterProcess* pRasterProc= NULL;
Cursor= crHourGlass;
CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&pRaster2);
CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL, IID_ILEADRasterProcess, (void**)&pRasterProc);
// Create the Raster2 bitmap->
MyWidth = LEADRasterView1->Raster->BitmapWidth;
MyHeight = LEADRasterView1->Raster->BitmapHeight;
MyBPS = LEADRasterView1->Raster->BitmapBits;
pRaster2->CreateBitmap (MyWidth, MyHeight, (short)MyBPS);
pRasterProc->Fill (pRaster2, RGB(0, 255, 0)); // fill with green
// Resize the LEADRasterView1 bitmap
ImageWidth = MyWidth * 0.3;
ImageHeight = MyHeight * 0.3;
pRasterProc->Size (LEADRasterView1->Raster, ImageWidth, ImageHeight, RESIZE_RESAMPLE);
// Initialize the variables used for multiple combines->
TestWidth = MyWidth; // Used for horizontal positioning
TestHeight = MyHeight; // Used for vertical positioning
VFactor = (MyHeight / ImageHeight) + 1; // Number spaces between images
VSpacing = ((int)MyHeight % ImageHeight) / VFactor; // Pixels between images
HFactor = (MyWidth / ImageWidth) + 1; // Number spaces between images
HSpacing = ((int)MyWidth % ImageWidth) / HFactor; // Pixels between images
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 = (CombineConstants)(CB_OP_ADD + CB_DST_0); // Operation flags used when combining images
// Do the loop that does the multiple combines
while (TestHeight > ImageHeight) // Vertical loop
{
DstT = MyHeight - TestHeight + VSpacing;
TestHeight = TestHeight - ImageHeight - VSpacing;
while (TestWidth > ImageWidth) //Horizontal loop
{
DstL = MyWidth - TestWidth + HSpacing;
TestWidth = TestWidth - ImageWidth - HSpacing;
pRasterProc->Combine (pRaster2, DstL, DstT, DstW, DstH, LEADRasterView1->Raster, SrcL, SrcT, MyOP);
}
TestWidth = MyWidth;
}
// Copy the Raster2 bitmap to LEADRasterView1
LEADRasterView1->Raster->Bitmap = pRaster2->Bitmap ;
//Set the image display size to match the LEADRasterView control
LEADRasterView1->SetDstRect (0, 0, LEADRasterView1->ScaleWidth, LEADRasterView1->ScaleHeight);
LEADRasterView1->SetDstClipRect (0, 0, LEADRasterView1->ScaleWidth, LEADRasterView1->ScaleHeight);
LEADRasterView1->ForceRepaint (); // Repaint the image
pRasterProc-> Release( );
pRaster2-> Release( );
Cursor= crDefault;