iam加载的图像大小略有不同。如何获得最小大小并将它们全部重新调整为该大小?
下面的代码是加载的图像->转换为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;发布于 2012-06-12 09:45:12
一旦开始将图像放入TImageList,就无法调整其大小,并且所有图像的大小必须相同。因此,您必须提前预加载所有图像,以便确定可用的最小尺寸,然后将任何较大的图像裁剪/拉伸到较小的尺寸,然后才能将最终图像加载到TImageList中。
让您的循环将所有TJPEGImage存储到TList或TObjectList中,而不是立即释放它们,然后您可以遍历该列表,计算最小大小,然后再次遍历列表,根据需要调整图像的大小,然后再次循环列表,将图像添加到TImageList,最后循环遍历列表,释放图像。
https://stackoverflow.com/questions/10989416
复制相似问题