mto*_*loo 4 delphi imagelist stretch
我有一个表包含图片字段中的图像,我将把它们放入ImageList.这是代码:
ImageList.Clear;
ItemsDts.First;
ImageBitmap:= TBitmap.Create;
try
while not ItemsDts.Eof do
begin
if not ItemsDtsPicture.IsNull then
begin
ItemsDtsPicture.SaveToFile(TempFileBitmap);
ImageBitmap.LoadFromFile(TempFileBitmap);
ImageList.Add(ImageBitmap, nil);
end;
ItemsDts.Next;
end;
finally
ImageBitmap.Free;
end;
Run Code Online (Sandbox Code Playgroud)
但是我对ImageList大小不同的图像有一些问题.
更新:我的问题是,当添加大于ImageList大小(32*32)的Image时,例如100*150它在连接到ImageList的组件中不能正确显示(例如在ListView中).似乎新添加的图像没有被拉伸但是被克隆.我希望像ImageList编辑器一样拉伸新图像.
我不知道ImageList是否提供了自动拉伸图像的属性.除非有人找到一些内置函数,否则您可以在将图像添加到ImageList之前自己展开图像.当你在它时,停止使用磁盘上的文件:TMemoryStream改为使用.像这样的东西:
var StretchedBMP: TBitmap;
MS: TMemoryStream;
ImageList.Clear;
ItemsDts.First;
StretchedBMP := TBitmap.Create;
try
// Prepare the stretched bmp's size
StretchedBMP.Width := ImageList.Width;
StretchedBMP.Height := ImageList.Height;
// Prepare the memory stream
MS := TMemoryStream.Create;
try
ImageBitmap:= TBitmap.Create;
try
while not ItemsDts.Eof do
begin
if not ItemsDtsPicture.IsNull then
begin
MS.Size := 0;
ItemsDtsPicture.SaveToStream(MS);
MS.Position := 0;
ImageBitmap.LoadFromStream(MS);
// Stretch the image
StretchedBMP.Canvas.StretchDraw(Rect(0, 0, StretchedBmp.Width-1, StretchedBmp.Height-1), ImageBitmap);
ImageList.Add(StretchedBmp, nil);
end;
ItemsDts.Next;
end;
finally MS.Free;
end;
finally StretchedBMP.Free;
end;
finally
ImageBitmap.Free;
end;
Run Code Online (Sandbox Code Playgroud)
PS:我在浏览器的窗口中编辑了你的代码.我不能保证它编译,但如果没有,它应该很容易修复.
| 归档时间: |
|
| 查看次数: |
3552 次 |
| 最近记录: |