Solved

Converting RTF (Contents of RichEdit) to Bitmap

Posted on 1997-05-14
3
1,424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

762 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