Author |
Topic  |
|
zerob
  
198 Posts |
Posted - Jul 03 2018 : 15:18:45
|
I've done some text output and encountered two strange bugs. The first one is with TextOutput... it creates a way too big big layer. And the second bug is with CropTransparentBorder.
If used multiple times, is shrinks all new layers more and more and more until it is 1 Line high. (I've printed out a 2 line Text with #13#10)
var crtl: Integer; begin // Create a new 0 size layer (it will be resized later) crtl := ImageEn1.LayersAdd(TIELayerKind.ielkImage,25,150,0,0); // Resize the layer to fit the text containing a line break. (isn't there a way to measure without outputting it?) // this resizing resizes the layer way to big. ImageEn1.Proc.TextOut(0, 0, 'This is a Test'#13''#10'Do what i say!', 'Century Gothic', 144, clWhite, [], 0, False, True); // Resize the bitmap to the layer size. ImageEn1.LayersFixSizes(crtl); // overwrite all with black ImageEn1.Proc.Fill(clBlack); // Write out the real text and remove autoresizing and add smoothing ImageEn1.Proc.TextOut(0, 0, 'This is a Test'#13''#10'Do what i say!', 'Century Gothic', 144, clWhite, [], 0, True, False); // copy the thing to the alpha channel to cut out black parts ImageEn1.LayersCopyToAlpha(crtl); // remove the way too big layer that TextOut created // this works the first time, but if you repeat this whole function multiple times, the layer shrinks more and more // until it removed the second line of the line break text 'This is a Test'#13''#10'Do what i say!' ImageEn1.Proc.CropTransparentBorder;
 |
|
xequte
    
39053 Posts |
Posted - Jul 03 2018 : 21:35:39
|
Hi
Sorry, I don't see the bug here.
If you textout at 0,0, then there will be blank space above the text. Cropping the transparency will then reduce the image height to "height - topblank - bottomblank". You then output again at 0,0 which creates more blank space at the top, and at the bottom some of the text will be off the image and lost. Do this enough times and there is nothing left.
It looks like you would be better to use a TIETextLayer which handles much of this automatically. After creating it, you can convert it to an image using:
https://www.imageen.com/help/TImageEnView.LayersConvertToImageLayers.html
Nigel Xequte Software www.imageen.com |
 |
|
zerob
  
198 Posts |
Posted - Jul 04 2018 : 01:24:09
|
Well, if i create that layer with a biger size, it also has the same issue. I thought the flag "bAutoEnlarge If the image is not large enough to fit the text it will be enlarged and filled with Background" would enlarge the Layer to fit the Text if too small.
I've "fixed" it now with creating a layer that has the same size as the background, which helps until the user uses a text size that is bigger. I also do some super sampling, so the text problem gets visible even earlyer. And i can't use a TextLayer as i do different other things to the layers.
crtl := ImageEn1.LayersAdd(TIELayerKind.ielkImage,25,150,ImageEn1.Layers[0].Width,ImageEn1.Layers[0].Height); |
 |
|
zerob
  
198 Posts |
Posted - Jul 04 2018 : 01:55:00
|
LayersAdd If the size and pixel format are not specified then the new layer assumes that of the current layer. This will use the smaller cropped former version of the text, and then the TextOut bAutoEnlarge doesn't resize the layer. So it shrinks and shrinks more. What does the bAutoEnlarge do then? And is there some way to measure the minimal space a TextOut would need, so i can create a large enought Layer? |
 |
|
xequte
    
39053 Posts |
Posted - Jul 04 2018 : 22:34:14
|
Sorry, I missed that. Yes, if bAutoEnlarge is enabled then this should not occur.
Actually, the issue is due to another parameter, bAntiAlias. First it is false, then true. The TextOut code in ImageEn now uses GDI+, whereas it previously used a TCanvas method. If bAntiAlias is false, ImageEn assumes you want the older method, so you get this issue.
For 8.0.1, we will ditch the legacy method, and use GDI+ even for non-antialiased text.
Nigel Xequte Software www.imageen.com
|
 |
|
|
Topic  |
|
|
|