Solved

# how to combine 4 bmp pictures into one jpg

Posted on 2011-04-24
Medium Priority
460 Views
Hi,
I`ve got 4 bmp files:
c:\test\foto1.bmp
c:\test\foto2.bmp
c:\test\foto3.bmp
c:\test\foto4.bmp
all files have the same sizes 320x240
I want to get one jpg file with size 640x480
0
Question by:Vaalar
• 2

LVL 24

Accepted Solution

jimyX earned 2000 total points
ID: 35456217
You can use "Canvas.CopyRect":
``````uses jpeg;

procedure TForm1.Button4Click(Sender: TObject);
var
jpg : TJPegImage;
Image:TImage;
img:TImage;
begin
jpg := TJpegImage.Create;
Image:=TImage.Create(nil);
img:=TImage.Create(nil);
try
Image.Width := img.Width * 2;   // or 640
Image.Height := img.Height * 2; // or  480
Image.Canvas.CopyRect(rect(0,0,Img.Width,Img.Height),Img.Canvas,rect(0,0,Img.Width,Img.Height));     // first quorter
Image.Canvas.CopyRect(rect(Img.Width,0,Img.Width *2,Img.Height),Img.Canvas,rect(0,0,Img.Width,Img.Height));   // second quorter
Image.Canvas.CopyRect(rect(0,Img.Height,Img.Width,Img.Height *2),Img.Canvas,rect(0,0,Img.Width,Img.Height));    // third quorter
Image.Canvas.CopyRect(rect(Img.Width,Img.Height,Img.Width *2,Img.Height *2),Img.Canvas,rect(0,0,Img.Width,Img.Height));    // forth quorter
jpg.Assign(Image.Picture.Graphic);
Image4.Picture.Graphic := jpg;  // just for test
finally
img.Free;
Image.Free;
jpg.Free;
end;
end;
``````
0

LVL 3

Expert Comment

ID: 35456220
I think something like this will work:
``````var TempBM, BM1.....: TBitmap;

...

etc...

TempBM:=TBitmap.create;
with TempBM do
begin
width:=640;
height:=480;
canvas.Draw(0, 0, BM1);
canvas.Draw(0, 320, BM2);
canvas.Draw(240, 0, BM3);
canvas.Draw(240, 320, BM4);
SaveToFile(....);
end;
TempBM.free;
etc...
``````
0

Author Closing Comment

ID: 35456665
Koen sry but Jimmy was first.
Your solution is also accurate but as I said...
0

LVL 3

Expert Comment

ID: 35458693
I think my solution uses less resources. It's not necessary to create a TImage. Anyway it will not make much difference.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
###### Suggested Courses
Course of the Month14 days, 9 hours left to enroll