In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Add some text to JPEG images .....

Xailer professional forum in English
ChrisGillard
Posts: 384
Joined: Tue May 01, 2007 5:49 pm

Add some text to JPEG images .....

Postby ChrisGillard » Tue Jul 25, 2017 12:14 pm

Hi,

I would like to take some existing JPEG image files and overlay the filename and a 'Title' as text on them.

Can I do this using GDI, just by displaying the file on some sort of canvas, drawing some text on that canvas and then saving the image back to a file?

I see we have TImage and TImageEditor using FreeImage in the Enterprise Edition .... is this the way to go?

Any general thoughts or simple example code would be much appreciated.

..... I've just researched the Samples folder and there are some useful Image display and edit examples. I should have looked there first .....

Not seeing any text drawing though?

Thanks

Chris
User avatar
ignacio
Site Admin
Posts: 8545
Joined: Mon Apr 06, 2015 8:00 pm
Location: Madrid, Spain
Contact:

Re: Add some text to JPEG images .....

Postby ignacio » Tue Jul 25, 2017 1:08 pm

Hello,

If you just want to put the text on top of the image you can use a label with its property lTransparent set to true. Another way is to use its OnPainted event. Something like this:

Code: Select all

METHOD Image1Painted( oSender, hDC, cPaintStruct ) CLASS TForm1

   LOCAL oCanvas AS CLASS TCanvas 
   oCanvas := TCanvas():NewFromDC( hDC )   
   oCanvas:TextOut(0,0, "Hello", 500, clBlack )   
   oCanvas:End()
   
RETURN Nil


In case you need to modify the image file adding some text information, I'm afraid you must deal with some 'C' code. This is the way to go:

- Create a compatible DC:
- Create a compatible Bitmap on memory with identical size of the original bitmap
- Copy (Bitblt function) the original bitmap to the compatible Bitmap
- Print the text on the compatilbe DC
- Save the compatible bitmap to file

If you need help on this please try to prototype the function you will need. Something like this:

Code: Select all

PutTextOnBitmap( cSourceFile, cTargetFile, nX, nY, cText, nColor )

And we will give a budge for that function.

BTW you may try to use the event OnPainted and then use the:

Code: Select all

XA_CaptureBitmap( <hWnd>, [<aRect>] | [<nLeft>, <nTop>, <nRight>, <nBottom>] ) --> hBitmap


Regards,
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
http://www.xailer.com
http://www.xailer.info
ChrisGillard
Posts: 384
Joined: Tue May 01, 2007 5:49 pm

Re: Add some text to JPEG images .....

Postby ChrisGillard » Tue Jul 25, 2017 1:28 pm

Hi Ignacio,

Thank you for your comprehensive reply.

Its the second example, the images are high resolution photos in .JPG files. I need to add the text to them and then re-save them at the same resolution.

I will work on your second example and see how far I get and then ask for more help.

I'm glad to see you released 5.0 a few days ago.

I have installed it and taken a quick look at some of the extra features but am continuing with 4.X for a little longer as I have a few projects which need to be done quickly.

I'm sure I will be back!

Regards

Chris

Return to “English”