Converting RTF (Contents of RichEdit) to Bitmap

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.
Who is Participating?
erajojConnect With a Mentor Commented:
This is NOT beautiful, but it copies the TRichEdit image
to a TImage:

procedure TMainForm.Button6Click(Sender: TObject);
  img: HDC;
  img := GetDC(RichEdit1.Handle);
    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

Hope this helps!

/// John

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
Rick_SAuthor Commented:
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.
All Courses

From novice to tech pro — start learning today.