?
Solved

how to combine 4 bmp pictures into one jpg

Posted on 2011-04-24
4
Medium Priority
?
460 Views
Last Modified: 2012-06-27
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
Please help
0
Comment
Question by:Vaalar
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
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
    img.Picture.LoadFromFile('c:\test\foto1.bmp');
    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
    img.Picture.LoadFromFile('c:\test\foto2.bmp');
    Image.Canvas.CopyRect(rect(Img.Width,0,Img.Width *2,Img.Height),Img.Canvas,rect(0,0,Img.Width,Img.Height));   // second quorter
    img.Picture.LoadFromFile('c:\test\foto3.bmp');
    Image.Canvas.CopyRect(rect(0,Img.Height,Img.Width,Img.Height *2),Img.Canvas,rect(0,0,Img.Width,Img.Height));    // third quorter
    img.Picture.LoadFromFile('c:\test\foto4.bmp');
    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;

Open in new window

0
 
LVL 3

Expert Comment

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

...

BM1:=TBitmap.create; BM1.LoadFromFile(...)
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...

Open in new window

0
 

Author Closing Comment

by:Vaalar
ID: 35456665
Koen sry but Jimmy was first.
Your solution is also accurate but as I said...
thx for your help
0
 
LVL 3

Expert Comment

by:KoenVandemoortel
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question