iam加载的图像大小略有不同。我怎样才能获得最小的尺寸,并将它们全部重新调整到这个尺寸?加载到TImageList中的不同大小图像
下面的代码是图像的加载 - >转换为bmp - >增加了图像列表
后约3的图像提示错误无效图像尺寸。由于图像尺寸太大,我在开始时给了imagelist的大小。
procedure TForm1.LoadImages(const Dir: string);
var
z,i: Integer;
CurFileName: string;
JpgIn: TJPEGImage;
BmpOut: TBitmap;
begin
i := 0;
z := 1;
while True do
begin
CurFileName := Format('%s%d.jpg',
[IncludeTrailingPathDelimiter(Dir), i]);
if not FileExists(CurFileName) then
Break;
JpgIn := TJPEGImage.Create;
try
JpgIn.LoadFromFile(CurFileName);
if z = 1 then
begin
ImageList1.SetSize(jpgin.width, jpgin.Height);
z := 0;
end;
BmpOut := TBitmap.Create;
try
BmpOut.Assign(JpgIn);
ImageList1.Add(BmpOut, nil);
finally
BmpOut.Free;
end;
finally
JpgIn.Free;
end;
Inc(i);
end;
if ImageList1.Count > 0 then
begin
BmpOut := TBitmap.Create;
try
ImageList1.GetBitmap(1, BmpOut);
zimage1.Bitmap.Assign(bmpout);
zimage1.Repaint;
finally
BmpOut.Free;
end;
end;
end;
我看到过你可以将TImageList设置为遇到的最大尺寸,然后将各个图像宽高比之外的像素设置为透明背景颜色。但为此我仍然需要知道遇到的最大尺寸。其中每次都会有所不同 –
您可能刚刚链接到上一个问题,以供将来参考,并在此处询问后续问题。雷米提出了一个解决方案的想法;我会解释这个问题。如果您在开始添加图像后更改图像列表的大小,图像列表将被清除,因此您无法更改大小。因此添加不同大小的图像会引发异常,因为图像列表在内部是作为单个宽图像(第一个图像的宽度乘以图像计数)实现的。然后,这会失败,并显示一张非常大的图片。 –