ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Paint RichFormat Layer on a Bitmap Transparently

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
john_siggy@yahoo.com Posted - Oct 07 2019 : 13:14:38
Hi Nigel,

Trying to paint a RichText Layer onto a Background TBitmap with transparency. Below are two procedures that implement this with Delphi's TRichEdit control and a bitmap. Don't want to use layers because this procedure is called many times per second.

I have tried to assign a RichText Layer to Delphi's TRichEdit control but I get text without formatting. The text looks like a Memo control with it's one font. Control characters are revealed
(e.g. {\rtf1\ansi\deff0\deflang1033{\fonttbl{\f0\fswiss Arial;}...).

How to paint RichText Layer onto a bitmap with formatting preserved ??





///////////////////////////////////////////

procedure DrawRTF(DestDCHandle: HDC; const R: TRect;
  RichEdit: TRichEdit; PixelsPerInch: Integer);
var
  TwipsPerPixel: Integer;
  Range: TFormatRange;
begin
  TwipsPerPixel := 1440 div PixelsPerInch;
  with Range do
  begin
    hDC := DestDCHandle; {DC handle}
    hdcTarget := DestDCHandle; {ditto}
    {Convert the coordinates to twips (1/1440")}
    rc.Left := R.Left * TwipsPerPixel;
    rc.Top := R.Top * TwipsPerPixel;
    rc.Right := R.Right * TwipsPerPixel;
    rc.Bottom := R.Bottom * TwipsPerPixel;
    rcPage := rc;
    chrg.cpMin := 0;
    chrg.cpMax := -1; {RichEdit.GetTextLen;}
    {Free cached information}
    RichEdit.Perform(EM_FORMATRANGE, 0, 0);

    {First measure the text, to find out how high the format rectangle will be. The call sets fmtrange.rc.bottom to the actual height required, if all                 characters in the selected range will fit into a smaller rectangle}

    RichEdit.Perform(EM_FORMATRANGE, 0, DWord(@Range));
    {Now render the text}
    RichEdit.Perform(EM_FORMATRANGE, 1, DWord(@Range));
    {Free cached information}
    RichEdit.Perform(EM_FORMATRANGE, 0, 0);
  end;
end;




procedure Tfmain.Button1Click(Sender: TObject);
var
  RichEdit: TRichEdit;
  ExStyle: DWord;
  bmp: TBitmap;
  DestDCHandle: HDC;
begin
  RichEdit := TRichEdit.Create(Self);
  try
    RichEdit.Visible := False;
    RichEdit.Parent := Self;
    {Win2k, WinXP}
    ExStyle := GetWindowLong(RichEdit.Handle, GWL_EXSTYLE);
    ExStyle := ExStyle or WS_EX_TRANSPARENT;
    SetWindowLong(RichEdit.Handle, GWL_EXSTYLE, ExStyle);
    RichEdit.Lines.LoadFromFile('c:\JDS\Readme.rtf');
    bmp := TBitmap.Create;
    try
      bmp.LoadFromFile('c:\jds\TheBackGroundBmp.bmp');
      DestDCHandle := bmp.Canvas.Handle;
      {Win9x}
      SetBkMode(DestDCHandle, TRANSPARENT);
      DrawRTF(DestDCHandle, Rect(0, 0, bmp.Width, bmp.Height), RichEdit, 96);
      Image1.Picture.Assign(bmp);
      Image1.Refresh;
    finally
      bmp.Free;
    end;
  finally
    RichEdit.Free;
  end;
end;

//////////////////////////////////////
2   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Oct 10 2019 : 02:28:05
Hi

See the TIERichEdit.PaintTo method in iexRichEdit. It will draw transparently onto a bitmap.



Nigel
Xequte Software
www.imageen.com
john_siggy@yahoo.com Posted - Oct 07 2019 : 15:26:23
One solution is to copy from the RichText Layer to Delphi's TRichEdit control and then paint the bitmap. See code at end.

Is there a more direct way to paint the RichText Layer to a Bitmap??


ss := TStringStream.Create(TIETextLayer( ImageEnView1.Layers[1] ).RichText);
ss.Position := 0;
RichEdit.Lines.LoadFromStream(ss);
RichEdit.WordWrap := True;
ss.Free;