Einzelnen Beitrag anzeigen

Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#2

Re: Text auf image zeichnen ?

  Alt 1. Aug 2008, 14:58
Hallo, eine andere Möglichkeit wäre mittels EM_FORMATRANGE.

Beispiel von P. Below:

Delphi-Quellcode:
uses
  RichEdit;

procedure RichEditToCanvas(RichEdit: TRichEdit; Canvas: TCanvas; PixelsPerInch: Integer);
var
  ImageCanvas: TCanvas;
  fmt: TFormatRange;
begin
  ImageCanvas := Canvas;
  with fmt do
  begin
    hdc := ImageCanvas.Handle;
    hdcTarget := hdc;
    // rect needs to be specified in twips (1/1440 inch) as unit
    rc := Rect(0, 0,
      ImageCanvas.ClipRect.Right * 1440 div PixelsPerInch,
      ImageCanvas.ClipRect.Bottom * 1440 div PixelsPerInch);
    rcPage := rc;
    chrg.cpMin := 0;
    chrg.cpMax := RichEdit.GetTextLen;
  end;
  SetBkMode(ImageCanvas.Handle, TRANSPARENT);
  RichEdit.Perform(EM_FORMATRANGE, 1, Integer(@fmt));
  // next call frees some cached data
  RichEdit.Perform(EM_FORMATRANGE, 0, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEditToCanvas(RichEdit1, Image1.Canvas, Self.PixelsPerInch);
  Image1.Refresh;
end;
Thomas
  Mit Zitat antworten Zitat