Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Combining Jpg Images


  • Please log in to reply
1 reply to this topic

#1 RubyS

RubyS

    CC Lurker

  • New Member
  • Pip
  • 5 posts

Posted 12 April 2012 - 11:52 PM

Hi,

I have a task to combine two jpg images to become one. One image is smaller size and wanted to put on top of the bigger one. I now how to load and show jpg file, but dont now to combine.


Thx before!
  • 0

#2 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 13 April 2012 - 12:28 AM

I am assuming you are using TJpegImage declared in unit jpeg. This graphic class does not have canvas, therefore you can not "draw" onto it. But we can use intermediary TBitmap to do the combination, then convert image in the TBitmap to TJpegImage. The pseudocode is something like the following.

var
  vFrontImg, vBkgImg, vResult: TJpegImage;
  vBmp: TBitmap;
begin
  LoadFrontImageFromFile;
  LoadBkgImageFromFile;
  CreateTempBitmap;
  DrawBkgImageToTempBitmap;
  DrawFrontImageToTempBitmap;
  AssignTempBitmapContentToResult;
  SaveResultToFile;
end;

There you are! now you have both jpeg images combined into one.

Hints:
  • for DrawBkgImageToTempBitmap and DrawFrontImageToTempBitmap, use TBitmap.Canvas.Draw(...); (see full description in delphi help)
  • for AssignTempBitmapContentToResult, you can simply use TJpegImage.Assign method.


-- Additional information
I have posted a tutorial related with combining images. Including JPG images. Check it out here.
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download