gpt4 book ai didi

delphi - 在Delphi中将拉伸(stretch)图像添加到ImageList

转载 作者:行者123 更新时间:2023-12-03 15:24:19 26 4
gpt4 key购买 nike

我有一个表,其中包含图片字段中的图像,我将把它们放入 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;

但是对于尺寸与 ImageList 尺寸不同的图像,我遇到了一些问题。

更新:我的问题是,当添加大于 ImageList 大小(32 * 32)的图像时,例如 100 * 150 它不会在连接到 ImageList 的组件中正确显示(例如在 ListView 中)。看来新添加的图像没有被拉伸(stretch),而是被裁剪了。我希望像在 ImageList Editor 中一样拉伸(stretch)新图像。

最佳答案

不知道ImageList是否提供了自动拉伸(stretch)图像的属性。除非有人找到一些内置的图像,否则您始终可以在将图像添加到 ImageList 之前自行拉伸(stretch)图像。当您这样做时,请停止使用磁盘上的文件:改用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;
<小时/>

PS:我在浏览器窗口中编辑了您的代码。我不能保证它能编译,但如果不能编译,应该很容易修复。

关于delphi - 在Delphi中将拉伸(stretch)图像添加到ImageList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6675841/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com