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( IncludeTrailingPathDelimiter( DestFolder ) + IntToStr( x ) + '_' + IntToStr( y ) + '.bmp' );
    end;

  outBmp.Free;
end;


TIEBitmap Assignment and Drawing Methods

TIEBitmap Methods
Method Mode Notes
Assign From TIEBitmap/TBitmap/TGraphic/TIcon Copy whole image
AssignImage From TIEBitmap Like assign, but does not copy the alpha channel
AssignRect From TIEBitmap/TBitmap Copy a specified rect
CopyAndConvertFormat From TIEBitmap Copy whole image
CopyRectTo To TIEBitmap Copy rect to another image (without scaling)
CopyWithMask1 To TIEBitmap Copy image using a mask to specify what is copied from the source
CopyWithMask2 To TIEBitmap Copy image using a mask to specify what is replaced in the destintation
DrawToTIEBitmap To TIEBitmap Copies all or part of the image to a specified position and/or size
MergeAlphaRectTo With TIEBitmap Merges all or part of two TIEBitmaps with alpha channels to a specified position using merge rules
MergeWithAlpha With TIEBitmap Merges all or part of two TIEBitmaps with alpha channels to a specified position
RenderToTIEBitmapEx To TIEBitmap Extended drawing of content to a TIEBitmap
StretchRectTo To TIEBitmap Copy rect to dest rect in another image (with scaling)
SwitchTo To TIEBitmap Move content from one TIEBitmap to another

TBitmap Methods
Method Mode Notes
Assign From TIEBitmap/TBitmap/TGraphic/TIcon Copy whole image
AssignRect From TIEBitmap/TBitmap Copy a specified rect
CopyFromTBitmap From TBitmap Copy whole image
CopyToTBitmap To TBitmap Copy whole image
RenderToTBitmapEx To TBitmap Extended drawing of content to a TBitmap

TCanvas Methods
Method Mode Notes
DrawToCanvas To TCanvas Copies whole image to canvas at specified position (ignoring the alpha channel)
DrawToCanvasWithAlpha To TCanvas Copies whole image to canvas at specified position (honoring the alpha channel)
RenderToCanvas To TCanvas Extended drawing of content to a TCanvas (ignoring the alpha channel)
RenderToCanvasWithAlpha To TCanvas Extended drawing of content to a TCanvas (honoring the alpha channel)