在DELPHI的RichTextEdit控件中,怎样实现插入图片的功能。
解决方案 »
- 跨窗体操作LISTVIEW总是报错
- 菜鸟问菜鸟问题……关于vclskin的……
- 高分求教怎样实现:类似于网络蚂蚁弹出一个在最上面的小窗口,然后将网页链接拖拉到此窗口中以获得其内容?
- 想找私活!
- 如何使窗体的所有Edit控件获得焦点时,Edit控件的属性Color为Blue?
- intraweb问题:form2如何使用form1中的变量?
- 还是定时问题!(初来乍到,请多多关照!)
- 关于在线程中创建和维护窗口的问题----〉〉〉〉〉〉〉〉高手进来!!!!(刚上任的版主一定要来哦!)
- 请教高手关于一个jsp的问题。
- 如何让自己写的浏览器和html文件关联后,双击html文件就用自己的浏览器打开了!
- 菜鸟在线等待求解!!!
- 急,急:请教: 用POP3控件当connect远程主机失败时,系统弹出出错信息程序异常终止,用try-excption 不行,怎么控制不能退出程序? 谢谢
没听说过
用WORD吧
可以在其中create TImage 吧
usesRichEdit;// Stream Callback functiontypeTEditStreamCallBack = function(dwCookie: Longint; pbBuff: PByte;cb: Longint; var pcb: Longint): DWORD;stdcall;TEditStream = recorddwCookie: Longint;dwError: Longint;pfnCallback: TEditStreamCallBack;end;// RichEdit TypetypeTMyRichEdit = TRxRichEdit;// EditStreamInCallback callback functionfunction EditStreamInCallback(dwCookie: Longint; pbBuff: PByte;cb: Longint; var pcb: Longint): DWORD; stdcall;// by P. BelowvartheStream: TStream;dataAvail: LongInt;begintheStream := TStream(dwCookie);with theStream dobegindataAvail := Size - Position;Result := 0;if dataAvail <= cb thenbeginpcb := read(pbBuff^, dataAvail);if pcb <> dataAvail thenResult := UINT(E_FAIL);endelsebeginpcb := read(pbBuff^, cb);if pcb <> cb thenResult := UINT(E_FAIL);end;end;end;// Insert Stream into RichEditprocedure PutRTFSelection(RichEdit: TMyRichEdit; SourceStream: TStream);// by P. BelowvarEditStream: TEditStream;beginwith EditStream dobegindwCookie := Longint(SourceStream);dwError := 0;pfnCallback := EditStreamInCallBack;end;RichEdit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, Longint(@EditStream));end;// Convert Bitmap to RTF Codefunction BitmapToRTF(pict: TBitmap): string;// by D3kvarbi, bb, rtf: string;bis, bbs: Cardinal;achar: ShortString;hexpict: string;I: Integer;beginGetDIBSizes(pict.Handle, bis, bbs);SetLength(bi, bis);SetLength(bb, bbs);GetDIB(pict.Handle, pict.Palette, PChar(bi)^, PChar(bb)^);rtf := '{{';SetLength(hexpict, (Length(bb) + Length(bi)) * 2);I := 2;for bis := 1 to Length(bi) dobeginachar := Format('%x', [Integer(bi[bis])]);if Length(achar) = 1 thenachar := '0' + achar;hexpict[I - 1] := achar[1];hexpict[I] := achar[2];Inc(I, 2);end;for bbs := 1 to Length(bb) dobeginachar := Format('%x', [Integer(bb[bbs])]);if Length(achar) = 1 thenachar := '0' + achar;hexpict[I - 1] := achar[1];hexpict[I] := achar[2];Inc(I, 2);end;rtf := rtf + hexpict + ' }}';Result := rtf;end; // Example to insert image from Image1 into RxRichEdit1procedure TForm1.Button1Click(Sender: TObject);varSS: TStringStream;BMP: TBitmap;beginBMP := TBitmap.Create;BMP := Image1.Picture.Bitmap;SS := TStringStream.Create(BitmapToRTF(BMP));tryPutRTFSelection(RxRichEdit1, SS);finallySS.Free;end;end;****************************************下面的代码可以不调用那个InsertObject的对话框而直接插入一张图片:varBmp:TBitmap;beginif not OpenPictureDialog1.Execute then exit;Bmp:=TBitmap.Create;Bmp.LoadFromFile(OpenPictureDialog1.FileName);Clipboard.Assign(BMP);RxRichEdit201.PasteFromClipboard;Bmp.Free;end;**************************************: TechnoFantasy(www.applevb.com)RichEdit中,插入图片代码:procedure proPrintRTFWithBMP(strCaption,strPic,strTitle:string;rtf:TRichEdit);{strText为要打印的文本 strCaption为打印标题 strPic为图像文件目录strTitle为要显示在图像右侧的图像标题}varFRTF:IRichEditOle;FOLE:IOLEObject;formatEtc:tagFORMATETC;FStorage :ISTORAGE;FClientSite:IOLECLIENTSITE;FLockBytes:ILockBytes;ReObject:TReObject;xt:TGuid;FTemp:IUnknown;strTemp:string;bCreateNew:boolean;ABMP:TBitmap;Ajpeg:TJpegImage;i:Longint;begin// rtfTemp:=TRichEdit.Create(frmPrintFrame);try{ with rtfTemp dobeginParent := frmPrintFrame;width:=200;height:=200;visible:=false;Text := strText;end; }//图片文件不存在,直接打印文本并退出if not fileexists(strPic)thenbeginPrintRichEdit(strCaption,rtf);exit;end;abmp:=TBitmap.Create;ajpeg:= TJpegImage.Create;tryif ExtractFileExt(strPic)='.jpg' thenbeginbCreateNew:=true;ajpeg.LoadFromFile(strPic);abmp.Assign(ajpeg);strTemp:=ExtractFilePath(strPic)+'0099www.bmp';abmp.SaveToFile(strTemp);for i:=1 to 30000 doapplication.ProcessMessages;endelsestrTemp:= strPic;finallyabmp.Free;ajpeg.free;abmp:=nil;ajpeg:=nil;end;sendmessage(rtf.handle,EM_GETOLEINTERFACE,0,LongInt(@FRTF));if not assigned(FRTF)thenbeginshowmessage('Error to get Richedit OLE interface');exit;end;//建立一个可以访问全局内存的Byte数组 FLockBytes//返回ILockBytes接口if CreateILockBytesOnHGlobal(0,true,FLockBytes)<>S_OK thenbeginshowmessage('Error to create Global Heap');exit;end;//建立一个混合文档存取对象if StgCreateDocfileOnILockBytes(FLockBytes,STGM_SHARE_EXCLUSIVE orSTGM_CREATE or STGM_READWRITE,0,FStorage)<>S_OK thenbeginshowmessage('Error to create storage');exit;end; formatEtc.cfFormat := 0;FormatEtc.ptd := nil;FormatEtc.dwAspect := DVASPECT_CONTENT;FormatEtc.lindex := -1;FormatEtc.tymed := TYMED_NULL;FRTF.GetClientSite(FClientSite);//从文件中创建一个OLE对象if OleCreateFromFile(GUID_NULL,PWideChar(WideString(strTemp)),IID_IUnknown,0,@formatEtc,FClientSite,FStorage,FOLE)<>S_OK thenbeginshowmessage('Error');exit;end;//现在的FOLE还是一个IUnKnown接口,将其转换为一个 IOleObject接口FTemp:=FOLE;FTemp.QueryInterface(IID_IOleObject, FOle);OleSetContainedObject(FOle, TRUE); //step 2reobject.cbStruct := sizeof(TReObject);FOLE.GetUserClassID(xt);ReObject.clsid := xt;reobject.cp := ULong(REO_CP_SELECTION);reobject.dvaspect := DVASPECT_CONTENT;reobject.dwFlags := ULong(REO_RESIZABLE) or ULong(REO_BELOWBASELINE);reobject.dwUser := 0;reobject.poleobj := FOle;reobject.polesite := FClientSite;reobject.pstg := FStorage;reobject.sizel.cx := 0;reobject.sizel.cy := 0;FRTF.InsertObject(reobject);PrintRichEdit(strCaption,rtf);finallyif bCreateNew thenDeletefile(strTemp);FRTF:=nil;FOLE:=nil;end;end;