Uses
Richedit; // rxrichedit
// rxrichedit
Type
TeditStreamCallback = Function (dwcookie: longint; pBBUFF: PBYTE;
CB: longint; var pcb: longint): DWORD;
STDCALL;
TeditStream = Record
DWCOOKIE: longint;
Dwerror: longint;
PfnCallback: TeditStreamCallback;
END;
// rxrichedit
Function EditStreamIncallback (dwcookie: longint; pBBUFF: PBYTE;
CB: Longint; VAR PCB: Longint): DWORD; stdcall;
VAR
THESTREAM: TSTREAM;
Dataavail: longint;
Begin
TheestReam: = TSTREAM (DWCookie);
With theestream do
Begin
Dataavail: = Size - POSITION;
Result: = 0;
If DataAvail <= CB THEN
Begin
PCB: = Read (PBBuff ^, DataAvail);
IF PCB <> DataAvail Then
Result: = uint (E_FAIL);
end
Else
Begin
PCB: = Read (PBBUFF ^, CB);
IF PCB <> CB THEN
Result: = uint (E_FAIL);
END;
END;
END;
// rxrichedit
Procedure PutrtfSelection (Richedit: TRXRICHEDIT; SourceStream: TSTREAM);
VAR
EDITSTREAM: TEDITSTREAM;
Begin
With EditStream Do
Begin
DWCOOKIE: = longint (SourceStream);
Dwerror: = 0;
Pfncallback: = EditStreamIncallback;
END;
Richedit.perform (em_streamin, sf_rtf or sff_selection, longint (@EDITSTREAM));
END;
Function BMPTORTF (Pict: Tbitmap): String;
Var // richedit98 rxrichedit
BI, BB, RTF: String;
BIS, BBS: cardinal
Achar: shortstring;
HEXPICT: STRING;
I: integer;
Begin
Pict.pixelformat: = pf8bit; // I am using 256 color image
GetDibsizes (Pict.handle, Bis, BBS);
SETLENGTH (BI, BI);
SETLENGTH (BB, BBS);
GetDib (Pict.Handle, Pict.palette, Pchar (BI) ^, PCHAR (BB) ^);
RTF: = '{/ RTF1 {/ PICT / DIBITMAP' # 13 # 10; // RTF head ause
SETLENGTH (HexPict, (Length (BB) Length (BI)) * 2);
I: = 2;
For bis: = 1 to Length (BI) DO
Begin
Achar: = format ('% x', [INTEGER (Bi [bis])]); if longth (acha) = 1 THEN
Achar: = '0' achar;
HEXPICT [i - 1]: = achar [1];
HEXPICT [I]: = ACHAR [2];
INC (I, 2);
END;
For bbs: = 1 to Length (bb) DO
Begin
Achar: = format ('% x', [Integer (BB [BBS])]);
if Length (Achar) = 1 THEN
Achar: = '0' achar;
HEXPICT [i - 1]: = achar [1];
HEXPICT [I]: = ACHAR [2];
INC (I, 2);
END;
RTF: = RTF HEXPICT '}}';
RESULT: = RTF;
END;
// - RXRICHEDIT
Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT);
VAR
Temp: tstringstream;
Begin
Temp: = tstringstream.create (bmptortf (image1.picture.bitmap);
Try
PutrtfSelection (rxrichedit1, temp);
Finally
Temp.free;
END;
END;
// --- richedit98
Procedure TFORM1.BUTTON2CLICK (Sender: TOBJECT);
Begin
Richedit981.rtfselText: = bmptortf (image1.picture.bitmap);
END;
Insert static JPEG, GIF (TGIFIMAGE) can be converted into Tbitmap format, and dynamically need to write GIF OLE