各位前辈好,我想在form1中加入ImageList,ComboBoxEx和RxRichEdit。ImageList中添加了许多表情图片,ComboBoxEx用于显示ImageList中图片,通过选择ComboBoxEx中的表情,让该表情显示在RxRichEdit中。
代码如下:怎么运行时RxRichEdit1中是空白啊??
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, (Length(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 TForm1.FormCreate(Sender: TObject);
var
Items:TComboExItem;
i:integer;
begin
ComboBoxEx1.Style:=csExDropDownList;
for i:=0 to ImageList1.Count-1 do
begin
Items:=ComboBoxEx1.ItemsEx.Add;
Items.Caption:=IntToStr(i);
Items.ImageIndex:=i;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Image:TBitmap;
begin
if ComboBoxEx1.ItemIndex<>-1 then
begin
Image:=TBitmap.Create;
ImageList1.GetBitmap(ComboBoxEx1.ItemIndex,Image);
InsertBitmapIntoRxRichEdit(Image,RxRichEdit1);
Image.Free;
end;
end;
代码如下:怎么运行时RxRichEdit1中是空白啊??
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, (Length(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 TForm1.FormCreate(Sender: TObject);
var
Items:TComboExItem;
i:integer;
begin
ComboBoxEx1.Style:=csExDropDownList;
for i:=0 to ImageList1.Count-1 do
begin
Items:=ComboBoxEx1.ItemsEx.Add;
Items.Caption:=IntToStr(i);
Items.ImageIndex:=i;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Image:TBitmap;
begin
if ComboBoxEx1.ItemIndex<>-1 then
begin
Image:=TBitmap.Create;
ImageList1.GetBitmap(ComboBoxEx1.ItemIndex,Image);
InsertBitmapIntoRxRichEdit(Image,RxRichEdit1);
Image.Free;
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货