Вниз
Скачать: CL | DM;

Картинка в Richedit   Найти похожие ветки 

 
Stas1   (2003-12-09 17:46) [0]

Можно ли вставить картинку в RichEdit?
Если да, то как? Если нет, то что посоветуете в замен?
Мне нужно в текстовое поле вставить картинку.
Спасибо!


 
Adoon   (2003-12-09 17:59) [1]

function BitmapToRTF(pict: TBitmap): string;
var
bi,bb,rtf: string;
bis,bbs: Cardinal;
achar: ShortString;
hexpict: string;
I: Integer;
begin
GetDIBSizes(pict.Handle,bis,bbs);
SetLength(bi,bis);
SetLength(bb,bbs);
GetDIB(pict.Handle,pict.Palette,PChar(bi)^,PChar(bb)^);
rtf := "{\rtf1 {\pict\dibitmap ";
SetLength(hexpict,(Length(bb) + Length(bi)) * 2);
I := 2;
for bis := 1 to Length(bi) do
begin
achar := Format("%x",[Integer(bi[bis])]);
if Length(achar) = 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;

procedure TCourseForm.InsertPictureClick(Sender: TObject);
VAR i: Integer;
SS:TStringStream;
P: TPicture;
BMP: TBitMap;
jpg: TJpegImage;
BEGIN
if OpenPictureDlg.Execute then begin
try
if (Pos(".bmp", OpenPictureDlg.FileName) > 0) then begin
BMP := TBitMap.Create;
P := TPicture.Create;
P.LoadFromFile(OpenPictureDlg.FileName);
BMP.Assign(P.Bitmap);
SS := TStringStream.Create(BitmapToRTF(BMP));
try
RichEdit.PlainText := False;
RichEdit.StreamMode := [smSelection];
RichEdit.Lines.LoadFromStream(SS);
RichEdit.StreamMode := [];
finally
SS.Free;
BMP.Free;
P.Free;
end
end
else begin
jpg := TJPEGImage.Create;
jpg.LoadFromFile(OpenPictureDlg.FileName);
BMP := TBitMap.Create;
BMP.Assign(jpg);
SS := TStringStream.Create(BitmapToRTF(BMP));
try
RichEdit.PlainText := False;
RichEdit.StreamMode := [smSelection];
RichEdit.Lines.LoadFromStream(SS);
RichEdit.StreamMode := [];
finally
SS.Free;
jpg.Free;
BMP.Free;
end
end;
finally
end;
end;
end;



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.013 c
1-75240
The ZEuS
2003-12-10 17:24
2003.12.23
проблемы с показом модальной формы из DLL


14-75371
Petrovich
2003-11-28 23:37
2003.12.23
Ссылки


9-75065
loto
2003-05-28 20:49
2003.12.23
(OpenGL) вращение и перемещение объекта в glCallList(ListID)


14-75329
Мазут Береговой
2003-12-02 04:18
2003.12.23
Эта ветка чи-иста-а для любознательных па-ацанов!...


1-75231
wnew
2003-12-10 20:36
2003.12.23
TPaintBox и TFrame




   Наверх