Solved

Converting RTF (Contents of RichEdit) to Bitmap

Posted on 1997-05-14
3
1,391 Views
Last Modified: 2013-12-03
How can I convert the contents of RichEdit to a Bitmap in an efficient manner? The ideal situation would be to read a rich text file from memory and then convert to a Bitmap.
0
Comment
Question by:Rick_S
3 Comments
 

Expert Comment

by:kangadru
ID: 1336239
Though I haven't tried this, I imagine the easiest way would be to print the RTF to a TBitmap.Canvas manually using TextOut and manually setting the properties.  I don't think there is a way to just designate the RTF Print Canvas short of rewriting your own TRichEdit based on the TcustomRichEdit and overriding the Print routine there to output to a TBitmap.Canvas instead of the Default PRinter DC (if you have the VCL Source, lookup TRichEdit.Print to see how they do it). I know it's an ugly solution but it is the only way I am aware of to do a bitmap from a RichEdit as the PainTo call does nothing more than display a bitmap of the control itself not the contents therofAndy
0
 
LVL 4

Accepted Solution

by:
erajoj earned 110 total points
ID: 1336240
This is NOT beautiful, but it copies the TRichEdit image
to a TImage:

procedure TMainForm.Button6Click(Sender: TObject);
var
  img: HDC;
begin
  img := GetDC(RichEdit1.Handle);
  BitBlt(
    Image1.Canvas.Handle,      // handle of destination device context
    0,                    // x-coordinate of destination rectangle's upper-left corner
    0,                    // y-coordinate of destination rectangle's upper-left corner
    RichEdit1.Width,  // width of destination rectangle
    RichEdit1.Height, // height of destination rectangle
    img,            // handle of source device context
    0,                    // x-coordinate of source rectangle's upper-left corner
    0,                    // y-coordinate of source rectangle's upper-left corner
    SRCCOPY             // raster operation code
   );
   Image1.Refresh;
end;

Hope this helps!

/// John

0
 

Author Comment

by:Rick_S
ID: 1336241
That works good but maybe is wasn't very clear...  I need to do this without the RichEdit component visable the example above didn't work when the 'RichEdit1.Visible := False' for obvious reasons.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
code issue 8 100
Help on project with Soap 10 48
Run video youtube webbrowse 10 58
Making delphi communicate with a c# service 16 91
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now