Solved

Converting RTF (Contents of RichEdit) to Bitmap

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

770 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