一个在Listbox中加入图片的问题??大家过年好!

yaojin2002cn 2004-01-14 03:21:31
在给Listbox中加入图片时,遇到的困难,下面是我的做法!
请问怎样才能把Jpg,ico等其他格式的加入进来~?
1、我先在SpeedButton1Click中做的事情
procedure TForm1.SpeedButton1Click(Sender: TObject);
VAR bitmap:Tbitmap;
txt:string;
begin
bitmap:=tbitmap.Create(self);
try
bitmap.LoadFromFile(DirectoryListBox1.Directory+'\'+Edit1.Text);
Except
bitmap:=nil;
end;
listbox1.Items.AddObject(Edit2.Text,bitmap);
end;
2在ListBox1MeasureItem中做的事情
procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
Height:=20;
end;
3在ListBox1DrawItem中做的事情
procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
VAR itmap:Tbitmap;
pos:Integer;
begin
with control as TListbox do
begin
canvas.FillRect(rect);
itmap:=Tbitmap(Items.Objects[index]);
pos:=0;
if itmap<>nil then
begin
canvas.brushcopy(bounds(rect.left+2,rect.top+2,itmap.Width,itmap.Height),itmap,bounds(0,0,itmap.width,itmap.height),clred);
pos:=itmap.Width+8
end;
canvas.TextOut(rect.left+pos,rect.Top,items[index]);
end;
end;
以上的能实现bitmap的图片,怎样加入其他格式的呢》》?
...全文
115 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaojin2002cn 2004-01-15
  • 打赏
  • 举报
回复
使用第三方控件?
是什么控件呢?
yaojin2002cn 2004-01-15
  • 打赏
  • 举报
回复
我也试用个使用Jpeg
我想先转成Bitmap的格式
也没有成功!
我是这样做的:
Var bitmap:Tbitmap;
jpg:TJPEGImage;
beign
Jpg :=TJPEGImage.Create;
Jpg.LoadFromFile('d:\8088.JPG');
bitmap:=TBitmap.Create;
Bitmap.Assign(Jpg);
...
end;
是这样吗?
S.F. 2004-01-14
  • 打赏
  • 举报
回复
要支持jpg,请uses jpeg即可
Hedonism 2004-01-14
  • 打赏
  • 举报
回复
帮你先试试,行,则发出来
tzh2001 2004-01-14
  • 打赏
  • 举报
回复
先转成Bitmap不就行了吗?
lgqTiger 2004-01-14
  • 打赏
  • 举报
回复
我比较喜欢用第三方的空间来完成,
好用有快捷!

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧