var X, Y: Integer; // column and row iterators DstArea: TRect; // destination area Margins: TSize; // calculated margins between images ImgSize: TSize; // size of a single image ImgOrig: TPoint; // target image origin CntCols: Integer; // actual number of columns CntRows: Integer; // actual number of rows MaxRows: Integer; // maximum number of columns that can be placed in the area MaxCols: Integer; // maximum number of rows that can be placed in the area begin DstArea := ???; MaxCols := ???; MaxRows := ???; ImgSize.cx := ???; ImgSize.cy := ???; CntCols := Min(DstArea.Width div ImgSize.cx, MaxCols); CntRows := Min(DstArea.Height div ImgSize.cy, MaxRows); Margins.cx := (DstArea.Width - (CntCols * ImgSize.cx)) div (CntCols + 1); Margins.cy := (DstArea.Height - (CntRows * ImgSize.cy)) div (CntRows + 1); for X := 0 to CntCols - 1 do for Y := 0 to CntRows - 1 do begin ImgOrig.X := (X * ImgSize.cx) + ((X + 1) * Margins.cx); ImgOrig.Y := (Y * ImgSize.cy) + ((Y + 1) * Margins.cy); SomeCanvas.Draw(ImgOrig.X, ImgOrig.Y, SomeImage); end; end;