ImageEn, unit iexBitmaps

TIEBitmap.CopyRectTo

TIEBitmap.CopyRectTo


Declaration


procedure CopyRectTo(Dest: TIEBitmap; SrcX, SrcY, DstX, DstY: integer; RectWidth, RectHeight: integer; CopyAlpha: boolean = false);


Description


Copies a rectangle to the Dest image.

Parameter Description
Dest Destination bitmap. Must have same PixelFormat as the source image
SrcX Left source position
SrcY Top source position
DstX Left destination position. Can be negative (cut top-left rectangle and reduces size)
DstY Top destination position
RectWidth Width of rectangle to copy
RectHeight Height of rectangle to copy
CopyAlpha If true alpha channel is also copied (only if the source bitmap has an alpha channel)



Example


// Method that takes an image, splits it into multiple cells and saves each cell to file
procedure SplitImage(Bitmap: TIEBitmap; cols, rows: integer; DestFolder: string);
var
  cellWidth, cellHeight: Double;
  x,y : Integer;
  outBmp: TIEBitmap;
begin
  cellWidth := Bitmap.Width / cols;
  cellHeight := Bitmap.Height / rows;

  outBmp := TIEBitmap.Create;
  outBmp.Allocate( Round( cellWidth ), Round( cellHeight ));

  for x := 0 to cols do
    for y := 0 to rows do
    begin
      Bitmap.CopyRectTo( outBmp,
                         Round( cellWidth * x ), Round( cellHeight * y ),
                         0, 0,
                         Round( cellWidth ), Round( cellHeight ));
      outBmp.Write( IncludeTrailingBackSlash( DestFolder ) + IntToStr( x ) + '_' + IntToStr( y ) + '.bmp' );
    end;

  outBmp.Free;
end;