Einzelnen Beitrag anzeigen

Rapunzel

Registriert seit: 1. Mär 2019
48 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: FMX Problem bei Textausgabe auf Bitmap

  Alt 9. Jan 2022, 19:58
Vielen Dank, ich konnte mir gerade die Lösung über ein Image mit einer Multiresbitmap erschließen. Auf der Bitmap des Image funktioniert die Textausgabe. Bitmapscale ist das Zauberwort. Hier meine Lösung. Beide Textausgaben sind jetzt 100% identisch

Delphi-Quellcode:
procedure TfrmMain.PtBoxPaint(Sender: TObject; Canvas: TCanvas);
Var Bmp:TBitmap; SrcRc,TxtRc,DstRc:TRectF;
begin
  Canvas.Font.Size:=30;
  Bmp:=TBitmap.Create(1,1);
  Bmp.BitmapScale:=Canvas.Scale;
  // Damit Bmp.Canvas.Scale entsprechend BitmapScale gesetzt wird:
  Bmp.SetSize(Trunc(PtBox.Width*Canvas.Scale),Trunc(PtBox.Height*Canvas.Scale));
  Bmp.Clear(TAlphaColors.White);
  Bmp.Canvas.BeginScene;
  Bmp.Canvas.Fill.Color:=TAlphaColors.Black;
  Bmp.Canvas.Font.Assign(Canvas.Font);
  TxtRc:=TRectF.Create(10,10,PtBox.Width,PtBox.Height);
  Bmp.Canvas.FillText(TxtRc, 'Testtest', false, 1, [], TTextAlign.Leading, TTextAlign.Leading);
  Bmp.Canvas.HorzLine(0,100,50); // Aus Classhelper
  Bmp.Canvas.VertLine(0,100,50); // Aus Classhelper
  Bmp.Canvas.EndScene;
  SrcRc:=TRectF.Create(0,0,Bmp.Width,Bmp.Height);
  DstRc:=TRectF.Create(0,0,PtBox.Width,PtBox.Height);
  Canvas.DrawBitmap(Bmp, SrcRc, DstRc, 1);
  TxtRc:=TRectF.Create(10,35,PtBox.Width,PtBox.Height);
  Canvas.Fill.Color:=TAlphaColors.Black;
  Canvas.FillText(TxtRc, 'Testtest', false, 1, [], TTextAlign.Leading, TTextAlign.Leading);
  Bmp.Free;
end;
  Mit Zitat antworten Zitat