Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
How to render a TRichEdit text onto a canvas (TImage)
1 comments. Current rating: (1 votes). Leave comments and/ or rate it.
Question:
I need to render a TRichEdit text to a canvas in order to save it as an image file then. How can I achieve this?
Answer:
Call function RichEditToCanvas() and pass the TRichEdit control and the image control as shown in the button handler below. The third parameter (pixels per inch) remains unchanged.  | |  | |
implementation
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;
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));
RichEdit.Perform(EM_FORMATRANGE, 0, 0)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
RichEditToCanvas(RichEdit1, Image1.Canvas, Self.PixelsPerInch);
Image1.Refresh
end;
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|