Hi Craig
You can use the following helper methods to join two images:
(They will be included in iexHelperFunctions in the next update).
procedure IEJoinBitmaps(Dest: TIEBitmap; Src1, Src2: TIEBitmap; Vertical: Boolean; BGColor: TColor = clBlack);
var
imgLeft, imgTop: Integer;
totalWidth, totalHeight: Integer;
begin
if Vertical then
begin
totalWidth := max( Src1.Width, Src2.Width );
totalHeight := Src1.Height + Src2.Height;
end
else
begin
totalWidth := Src1.Width + Src2.Width;
totalHeight := max( Src1.Height, Src2.Height );
end;
Dest.IEInitialize( totalWidth, totalHeight, BGColor );
if Vertical then
begin
imgLeft := ( totalWidth - Src1.Width ) div 2;
imgTop := 0;
Src1.DrawToTIEBitmap( Dest, imgLeft, imgTop );
imgLeft := ( totalWidth - Src2.Width ) div 2;
imgTop := Src1.Height;
Src2.DrawToTIEBitmap( Dest, imgLeft, imgTop );
end
else
begin
imgLeft := 0;
imgTop := ( totalHeight - Src1.Height ) div 2;
Src1.DrawToTIEBitmap( Dest, imgLeft, imgTop );
imgLeft := Src1.Width;
imgTop := ( totalHeight - Src2.Height ) div 2;
Src2.DrawToTIEBitmap( Dest, imgLeft, imgTop );
end;
end;
procedure IEJoinBitmaps(Dest: TBitmap; Src1, Src2: TBitmap; Vertical: Boolean; BGColor: TColor = clBlack);
var
imgLeft, imgTop: Integer;
totalWidth, totalHeight: Integer;
begin
if Vertical then
begin
totalWidth := max( Src1.Width, Src2.Width );
totalHeight := Src1.Height + Src2.Height;
end
else
begin
totalWidth := Src1.Width + Src2.Width;
totalHeight := max( Src1.Height, Src2.Height );
end;
Dest.IEInitialize( totalWidth, totalHeight, BGColor );
if Vertical then
begin
imgLeft := ( totalWidth - Src1.Width ) div 2;
imgTop := 0;
Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src1.Width, imgTop + Src1.Height ),
Src1.Canvas,
Rect( 0, 0, Src1.Width, Src1.Height ));
imgLeft := ( totalWidth - Src2.Width ) div 2;
imgTop := Src1.Height;
Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src2.Width, imgTop + Src2.Height ),
Src2.Canvas,
Rect( 0, 0, Src2.Width, Src2.Height ));
end
else
begin
imgLeft := 0;
imgTop := ( totalHeight - Src1.Height ) div 2;
Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src1.Width, imgTop + Src1.Height ),
Src1.Canvas,
Rect( 0, 0, Src1.Width, Src1.Height ));
imgLeft := Src1.Width;
imgTop := ( totalHeight - Src2.Height ) div 2;
Dest.Canvas.CopyRect( Rect( imgLeft, imgTop, imgLeft + Src2.Width, imgTop + Src2.Height ),
Src2.Canvas,
Rect( 0, 0, Src2.Width, Src2.Height ));
end;
end;
Here's some example usage:
procedure TMain.Button1Click(Sender: TObject);
begin
ImageEnView1.LegacyBitmap := False;
ImageEnView2.LegacyBitmap := False;
ImageEnView3.LegacyBitmap := False;
ImageEnView1.IO.LoadFromFile( 'D:\_Testfiles\Image1.jpg' );
ImageEnView2.IO.LoadFromFile( 'D:\_Testfiles\Image2.bmp' );
IEJoinBitmaps( ImageEnView3.IEBitmap, ImageEnView1.IEBitmap, ImageEnView2.IEBitmap, False );
ImageEnView3.Update();
end;
Or see this demo:
attach/xequte/201772720408_JoinBitmaps.zip
49.47 KB
Nigel
Xequte Software
www.xequte.com
nigel@xequte.com