Recent

Author Topic: Rotating text in BGRA  (Read 529 times)

wp

  • Hero Member
  • *****
  • Posts: 12757
Rotating text in BGRA
« on: March 27, 2025, 01:25:38 pm »
Currently I am extending the LazMapViewer to handle rotated text. I thought it would be convenient to rotate the text around its center and implemented this feature in this way for the default drawer based on LazIntfImage.

There is also a drawing engine using BGRABitmap. And when I rotate the text here, I see that the rotation center is in the upper left text corner. Is there a way to set parameters such that rotation occurs around the center here, too?

DomingoGP

  • Jr. Member
  • **
  • Posts: 85
Re: Rotating text in BGRA
« Reply #1 on: March 27, 2025, 09:12:01 pm »
Hi wp

I guess You can use this property of bgrabitmap.

  Bitmap.FontVerticalAnchor := fvaCenter;

To draw text along lines like roads, streets and rivers I would use  Bitmap.TextOutCurved like this sample code.


Code: Pascal  [Select][+][-]
  1.  
  2. uses
  3.   BGRABitmap,BGRABitmapTypes,BGRAPath;
  4.  
  5. var
  6.   polyline:Array [0..3]Of TPointF=((x:10;y:60),(x:70;y:30),(x:200;y:30),(x:260;y:50));
  7.  
  8. procedure TForm1.Button1Click(Sender: TObject);
  9. var
  10.   bitmap:TBGRABitmap;
  11.   path2:TBGRAPath;
  12. begin
  13.   bitmap:=TBGRABitmap.Create(600,180,BGRA(255,255,255));
  14.   path2 := TBGRAPath.Create;
  15.   bitmap.DrawPolyLineAntialias(polyline,BGRA(0,0,0),2);
  16.   path2.polyline(polyline);
  17.   Bitmap.FontVerticalAnchor := fvaCenter;
  18.   Bitmap.TextOutCurved(path2, 'Sample rotated text', BGRA(255,0,0), taLeftJustify, 0);
  19.  
  20.   //bitmap.DrawLine(280,5,340,65,BGRA(0,0,0),true);
  21.   //bitmap.TextOutAngle(280,5, -450, 'Hello', BGRA(0,0,255), taLeftJustify);
  22.  
  23.   bitmap.FontVerticalAnchor := fvaTop;
  24.   path2.Free;
  25.   bitmap.Draw(Canvas,0,50);
  26.   bitmap.Free;
  27. end;    
  28.  

Regards
Domingo

wp

  • Hero Member
  • *****
  • Posts: 12757
Re: Rotating text in BGRA
« Reply #2 on: March 29, 2025, 01:13:52 am »
I found it: I need Bitmap.FontVerticalAnchor := fvaCenter, and taCenter as Align parameter in the Bitmap.TextOut call.

 

TinyPortal © 2005-2018