Einzelnen Beitrag anzeigen

Hawkeye219

Registriert seit: 18. Feb 2006
Ort: Stolberg
2.227 Beiträge
 
Delphi 2010 Professional
 
#17

Re: Bitmapgröße an Textgröße anpassen?

  Alt 5. Aug 2006, 13:22
Hallo Karstadt,

hier ist eine andere Lösung:

Delphi-Quellcode:
procedure GetTextImage (aText: string; var aBitmap: TBitmap);
var
  R : TRect;
begin
  with aBitmap.Canvas do
    begin
      SetRect(R, 0, 0, MaxInt, MaxInt);
      DrawText(Handle, PChar(aText), Length(aText), R, DT_CALCRECT);
      aBitmap.Width := R.Right - R.Left;
      aBitmap.Height := R.Bottom - R.Top;
      OffsetRect(R, -R.Left, -R.Top);
      DrawText(Handle, PChar(aText), Length(aText), R, 0);
    end;
end;
Die Routine kannst du folgendermaßen nutzen:

Delphi-Quellcode:
procedure Form1.Button1Click (Sender: TObject);
var
  BMP : TBitmap;
begin
  BMP := TBitmap.Create;
  try
    BMP.Canvas.Font.Assign (RichEdit1.Font);
    GetTextImage (RichEdit1.Text, BMP);
    Self.Canvas.Draw (0, 0, BMP);
  finally
    BMP.Free;
  end;
end;
Gruß Hawkeye
  Mit Zitat antworten Zitat