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 convert the content of a TRichEdit into a bitmap 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
29-Aug-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
112
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Does anyone know of a component or a few lines of code, that could turn the 
contents of a TRichText field (WIN32 RTF) into a bitmap?

Answer:

Add this in the unit your are developing:


1   uses
2     RichText;
3   
4   {For this demo add a RichEdit and an Image Control set the RichEdit change event to 
5   the lower code}
6   
7   procedure
8     OutputRTFToBmp(RichHolder: TRichEdit; ImageHolder: TBitmap; itemwidth, 
9   itemheight: real);
10  var
11    Range: TFormatRange;
12    TextBoundary: TRect;
13  begin
14    {Setup the Height and Width of our output}
15    ImageHolder.width := round(itemwidth * screen.PixelsPerInch);
16    ImageHolder.height := round(itemheight * screen.PixelsPerInch);
17    {Set the Size of the Rich Edit}
18    textboundary := rect(0, 0, round(itemwidth * 1440), round(itemheight * 1440));
19    {Set the Range record}
20    range.hdc := ImageHolder.Canvas.handle;
21    range.hdctarget := ImageHolder.Canvas.handle;
22    range.rc := textboundary;
23    range.rcpage := textboundary;
24    {Start at character zero}
25    range.chrg.cpMin := 0;
26    {Display all Characters}
27    range.chrg.cpMax := -1;
28    {Ask RTF to Draw}
29    Sendmessage(RichHolder.handle, EM_FORMATRANGE, 1, longint(@range));
30    {Cleanup RTF Cache}
31    sendmessage(RichHolder.handle, EM_FORMATRANGE, 0, 0);
32  end;
33  
34  procedure TForm1.RichEdit1Change(Sender: TObject);
35  begin
36    OutputRTFToBmp(RichEdit1, Image1.picture.bitmap, 2, 2);
37    {Display new stuff, this will flicker so you will have to double buffer}
38    image1.refresh;
39  end;



I use it on Metafiles then you can scale it also.

			
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