Create Bitmap, Size, and Combine example for Delphi
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.
var
sRet: Smallint;
DstT: Single;
DstL: Single;
SrcL: Single;
SrcT: Single;
DstW: Single;
DstH: Single;
MyWidth:Single;
MyHeight: Single;
MyBPS: Integer;
ImageWidth: Integer;
ImageHeight: Integer;
TestWidth: Integer;
TestHeight: Integer;
VFactor: Integer;
VSpacing: Integer;
HFactor: Integer;
HSpacing: Integer;
Raster2: LEADRaster;
MyOP: CombineConstants;
RasterProc: LEADRasterProcess;
begin
Cursor:= crHourglass;
Raster2:= CreateComObject (CLASS_LEADRaster) as LEADRaster;
RasterProc:= CreateComObject (CLASS_LEADRasterProcess ) as LEADRasterProcess;
// Create the Raster2 bitmap.
MyWidth := LEADRasterView1.Raster.BitmapWidth;
MyHeight := LEADRasterView1.Raster.BitmapHeight;
MyBPS := LEADRasterView1.Raster.BitmapBits;
Raster2.CreateBitmap (MyWidth, MyHeight, MyBPS);
RasterProc.Fill (Raster2, RGB(0, 255, 0)); // fill with green
// Resize the LEADRasterView1 bitmap
ImageWidth := Trunc(MyWidth * 0.3);
ImageHeight := Trunc(MyHeight * 0.3);
RasterProc.Size (LEADRasterView1.Raster, ImageWidth, ImageHeight, RESIZE_RESAMPLE);
// Initialize the variables used for multiple combines.
TestWidth := Trunc(MyWidth); // Used for horizontal positioning
TestHeight := Trunc(MyHeight); // Used for vertical positioning
VFactor := Trunc(MyHeight / ImageHeight) + 1; // Number spaces between images
VSpacing := Trunc((Trunc(MyHeight) Mod ImageHeight) / VFactor); // Pixels between images
HFactor := Trunc(MyWidth / ImageWidth) + 1; // Number spaces between images
HSpacing := Trunc((Trunc(MyWidth) Mod 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 := CB_OP_ADD + CB_DST_0; // Operation flags used when combining images
// Do the loop that does the multiple combines
while (TestHeight > ImageHeight) do // Vertical loop
begin
DstT := MyHeight - TestHeight + VSpacing;
TestHeight := TestHeight - ImageHeight - VSpacing;
while (TestWidth > ImageWidth) do //Horizontal loop
begin
DstL := MyWidth - TestWidth + HSpacing;
TestWidth := TestWidth - ImageWidth - HSpacing;
RasterProc.Combine (Raster2, DstL, DstT, DstW, DstH, LEADRasterView1.Raster, SrcL, SrcT, MyOP);
end;
TestWidth := Trunc(MyWidth);
end;
// Copy the Raster2 bitmap to LEADRasterView1
LEADRasterView1.Raster.Bitmap := Raster2.Bitmap ;
//Set the image display size to match the LEADRasterView control
LEADRasterView1.SetDstRect (0, 0, LEADRasterView1.ScaleWidth, LEADRasterView1.ScaleHeight, sRet);
LEADRasterView1.SetDstClipRect (0, 0, LEADRasterView1.ScaleWidth, LEADRasterView1.ScaleHeight, sRet);
LEADRasterView1.ForceRepaint (sRet); // Repaint the image
Cursor:= crDefault;
end;