Solved

Converting RTF (Contents of RichEdit) to Bitmap

Posted on 1997-05-14
3
1,379 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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, fr…
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now