ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Border and text overlay?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

933 Posts

Posted - Jun 15 2017 :  08:25:09  Show Profile  Reply
In a TImageEnView 7.0, which is the most simple way to programmatically:

• Add a small text overlay with (semi-transparent) background in the center of the image. "Semi-transparent background means" that the underlying image should slightly shine trough the background area of the text while the text itself should be completely opaque.

Something like this:



xequte

38616 Posts

Posted - Jun 15 2017 :  21:22:52  Show Profile  Reply
Hi

It would be easiest to use a text layer and then merge it into the image:

https://www.imageen.com/help/TIETextLayer.html


It would be something like:

with ImageEnView1 do
begin
  LayersAdd( 'Text', 'Arial Black', 42, clRed, [fsBold] );
  TIETextLayer( CurrentLayer ).SizeToText();
  CurrentLayer.PosX := IELayer_Pos_HCenter;
  CurrentLayer.PosY := IELayer_Pos_VCenter;

  CurrentLayer.FillColor  := clWhite;
  CurrentLayer.BorderColor := clNone;

  // Note: use Transparency if the image does not have an alpha channel
  CurrentLayer.Opacity := 0.7;

  LayersMergeAll();
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

PeterPanino

933 Posts

Posted - Jun 16 2017 :  08:00:01  Show Profile  Reply
Hi Nigel, unfortunately, this code did not work for me. (Compiler complained: Wrong overload for LayersAdd). This code did compile:

with DragDropForm.formDragDrop.imgCoverDrag do
  begin
    LayersAdd( 'DROP ME', 32, clRed, 'Arial Black', [fsBold],  IELayer_Pos_HCenter, IELayer_Pos_VCenter);
    TIETextLayer( CurrentLayer ).SizeToText();
    CurrentLayer.PosX := IELayer_Pos_HCenter;
    CurrentLayer.PosY := IELayer_Pos_VCenter;

    CurrentLayer.FillColor  := clWhite;
    CurrentLayer.BorderColor := clNone;

    // Note: use Transparency if the image does not have an alpha channel
    CurrentLayer.Opacity := 0.7;

    LayersMergeAll();
  end;


However, it makes the image smaller! And the text is not positioned in the center of the image!
Go to Top of Page

PeterPanino

933 Posts

Posted - Jun 16 2017 :  08:12:56  Show Profile  Reply
I removed the line:
LayersMergeAll();

Now the image size is correct. But the text is not horizontally center-aligned inside the white area. It is always left-aligned inside the white area. Even if I have:

TIETextLayer(CurrentLayer).Alignment := iejCenter;

This is how it looks:



You can see how the text is left-aligned inside the area.

This is the code I used:

with DragDropForm.formDragDrop.imgCoverDrag do
  begin
    LayersAdd('ME DROP', 10, clRed, 'Arial Black', [fsBold]);
    //TIETextLayer(CurrentLayer).AutoSize := True;
    TIETextLayer(CurrentLayer).Alignment := iejCenter;
    TIETextLayer(CurrentLayer).Text := 'DROP ME';
    CurrentLayer.FillColor := clWhite;
    CurrentLayer.BorderColor := clNone;
    CurrentLayer.PosX := IELayer_Pos_HCenter;
    CurrentLayer.PosY := IELayer_Pos_VCenter;
    TIETextLayer(CurrentLayer).SizeToText();
  end;


And the text is not exactly vertically centered in the white area either.
Go to Top of Page

w2m

USA
1990 Posts

Posted - Jun 16 2017 :  10:55:01  Show Profile  Reply
TIETextLayer(ImageEnView.CurrentLayer).Alignment := iejCenter;
will center the text horizontally. I have found that when the Textlayer Alignment property is set to iejCenter then text is "approximately centered' but it is not centered accurately. It appears that the blank space on the right side of the text is always wider than the blank space to the left side of the text. I have also found that when an alignment of iejJustify is used the text alignment is not changed at all. In some cases you may want to use an alignment of iejRight.

While the alignment works, the alignment is not perfect... at least from my testing. Perhaps the horizontal and vertical text alignment code can be improved a little for iejCenter and iejJustify to be more accurate.

You can also change the font to see if that the alignment is improved. Some fonts may produce the problem while other fonts seem to work better than others.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38616 Posts

Posted - Jun 18 2017 :  22:22:54  Show Profile  Reply
Hi

Yes, unfortunately GdipMeasureString often overestimates the size of text. In that case it is given as 73 x 20. Hence the extra padding.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: