在给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的图片,怎样加入其他格式的呢》》?
请问怎样才能把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的图片,怎样加入其他格式的呢》》?
解决方案 »
- IdTCPServer向IdTCPClient发送消息的一个功能,AThread.Connection.WriteLn(inttostr(i))出错
- 怎么在启动IE的同时修改IE的缓存目录
- 无法获取dll的传出参数,有经验的帮忙!
- 如何实现照片自动剪切?
- 惨啊!
- 怎么到dbgrideh中列中的选中的picklist的值,或者说怎么得到dbgrideh通过picklist修改的单元格的值
- 请问控件QRDBText能否换行?
- 呵呵,问个和编程无关的问题,100分也(关于最终幻想的MTV)
- 用两个query同时对一个表进行查询,然后在报表中显示,为什么有一个query结果不对?(内详)
- 在delphi中,如何用程序实现能调出windows控制面板的内容.
- 请教屏蔽弹出式窗口的问题
- 有用过TEkRTF的朋友进来看看,有个很头疼的问题
我想先转成Bitmap的格式
也没有成功!
我是这样做的:
Var bitmap:Tbitmap;
jpg:TJPEGImage;
beign
Jpg :=TJPEGImage.Create;
Jpg.LoadFromFile('d:\8088.JPG');
bitmap:=TBitmap.Create;
Bitmap.Assign(Jpg);
...
end;
是这样吗?