Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create a *.jpg image from a TRichEdit Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
04-Mar-03
Category
Reporting /Printing
Language
Delphi 3.x
Views
83
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Lou Adler

How to create a *.jpg image from a TRichEdit

Answer:

1   uses
2     RichEdit;
3   
4   procedure RichEditToJPEG(const aRichEdit: TRichEdit; const aJPEGImage: TJPEGImage);
5   var
6     lBMP: TBitmap;
7     liStyle: Integer;
8     liExStyle: Integer;
9     lR: TRect;
10    liTwipsPerPixel: Integer;
11    lfrFormatRange: TFormatRange; { Defined in RichEdit }
12  begin
13    lBMP := TBitmap.Create;
14    try
15      lBMP.Height := aRichEdit.Height;
16      lBMP.Width := aRichEdit.Width;
17      { Paint the richedit control's border }
18      aRichEdit.PaintTo(lBMP.Canvas.Handle, 0, 0);
19      { Store the richedit's window styles }
20      liStyle := GetWindowLong(aRichEdit.Handle, GWL_STYLE);
21      liExStyle := GetWindowLong(aRichEdit.Handle, GWL_EXSTYLE);
22      { Get canvas rect and adjust for the richedit's border if necessary }
23      lR := lBMP.Canvas.ClipRect;
24      if ((liStyle and WS_BORDER) <> 0) or ((liExStyle and WS_EX_CLIENTEDGE) <> 0) 
25  then
26      begin
27        Inc(lR.Left, GetSystemMetrics(SM_CXEDGE));
28        Inc(lR.Top, GetSystemMetrics(SM_CYEDGE));
29        Dec(lR.Right, lR.Left);
30        Dec(lR.Bottom, lR.Top);
31      end;
32      { Adjust richedit's border by another pixel }
33      InflateRect(lR, -1, -1);
34      { We need twips to calculate sizes }
35      liTwipsPerPixel := 1400 div Screen.PixelsPerInch;
36      { Fill the TFormatRange record }
37      with lfrFormatRange do
38      begin
39        hdc := lBMP.Canvas.Handle;
40        hdcTarget := lBMP.Canvas.Handle;
41        { Convert the coordinates to twips }
42        rc := Rect(lR.Left * liTwipsPerPixel, lR.Top * liTwipsPerPixel,
43          lR.Right * liTwipsPerPixel, lR.Bottom * liTwipsPerPixel);
44        rcPage := rc;
45        chrg.cpMin := 0;
46        chrg.cpMax := -1;
47      end;
48      aRichEdit.Perform(EM_FORMATRANGE, 0, 0);
49      aRichEdit.Perform(EM_FORMATRANGE, 0, DWORD(@lfrFormatRange));
50      aRichEdit.Perform(EM_FORMATRANGE, 1, DWORD(@lfrFormatRange));
51      aRichEdit.Perform(EM_FORMATRANGE, 0, 0);
52      aJPEGImage.Assign(lBMP);
53    finally
54      lBMP.Free;
55    end;
56  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC