Insert the perfect solution for the image in the RXRICHEDIT (not using a clipboard)

zhaozj2021-02-11  185

The routines are as follows:

Set up the control RXRICHEDIT1 and Button1 on the Form1.

InsertbitMapintorxRichEdit uses the Button1Click method.

unit Unit1; interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, RxRichEd; type TForm1 = class (TForm) Button1: TButton; RxRichEdit1: TRxRichEdit; procedure Button1Click (Sender: TObject) ; private {Private declarations} public {public declarations} end; var Form1: TForm1; implementationuses JPEG; {$ R * .dfm} function ConvertBitmapToRTF (const Bitmap: TBitmap): string; var bi, bb: string; bis, bbs: Cardinal; ACHAR: STRING [2]; buffer: string; i: integer; type pword = ^ Word; Begin getDibsizes (Bitmap.handle, BIS, BBS); SetLength (BI, BIS); setLength (BB, BBS); getDib (BitMap.Handle, Bitmap.Palette, Pchar (BI) ^, Pchar (BB) ^); SETLENGTH (Buffer, (BB) Length (BI)) * 2); i: = 1; for bis: = 1 TO Length (BI) Do Begin Achar: = INTTOHEX (Integer (Bi [Bis]), 2); PWORD (@Buffer [i]) ^: = Pword (@achar [1]) ^; INC (i, 2 ); End; for bbs: = 1 to length (bb) do begin achar: = INTTOHEX (Integer (BB [BBS]), 2); PWORD (@Buffer [i]) ^: = PWORD (@ACHAR [1]) ^; Inc (i, 2); end; result: = '{/ rtf1 {/ pict / dibitmap' buffer '}}' ; end; procedure InsertBitmapIntoRxRichEdit (const Bitmap: TBitmap; const RxRichEdit: TRxRichEdit); overload; begin RxRichEdit.SelText: = ConvertBitmapToRTF (Bitmap); RxRichEdit.SelLength: = 0; RxRichEdit.SelStart: = RxRichEdit.SelStart 1; end; procedure InsertBitmapIntoRxRichEdit (const GraphicFileName: string; const RxRichEdit: TRxRichEdit); overload; var Bitmap: TBitmap; Graphic: TPicture; begin Graphic: = TPicture.Create; try Graphic.LoadFromFile (GraphicFileName);

转载请注明原文地址:https://www.9cbs.com/read-5159.html

New Post(0)