我将一些图像加载到对象列表中,然后尝试调用它们。但它不显示图像?
procedure TForm1.LoadImages(const Dir: string);
var
i: Integer;
CurFileName: string;
JpgIn: TJPEGImage;
BmpOut: TBitmap;
begin
//sets index for object list
CurIdx := -1;
i := 0;
while True do
begin
//gets current folder
CurFileName := Format('%s%d.jpg',
[IncludeTrailingPathDelimiter(Dir), i]);
if not FileExists(CurFileName) then
Break;
//creates jpgin
JpgIn := TJPEGImage.Create;
try
//loads jpgin
JpgIn.LoadFromFile(CurFileName);
//creates TBitmap and sets width to same as jpgs
BmpOut := TBitmap.Create;
bmpout.Width := jpgin.Width;
bmpout.Height := jpgin.Height;
try
BmpOut.Assign(JpgIn);
//if i assign it here it works, showing last image of course
//zimage1.Bitmap.Width := bmpout.Width;
//zimage1.Bitmap.Height := bmpout.Height;
//ZImage1.Bitmap.Assign(bmpout);
//adds 1 to index for object list. thus starting at 0
curIdx := curIdx+1;
//add bitmap to objectlist
CurIdx:= mylist.Add(TBitmap(bmpout));
finally
//free bitmap and jpg
BmpOut.Free;
end;
finally
JpgIn.Free;
end;
Inc(i);
end;
//makes sure cout is above 0
if mylist.Count > 0 then
begin
//create bitmap
BmpOut := TBitmap.Create;
try
//sets width and heigh of bitmap before getting image
bmpout.Height := TBitmap(mylist[curidx]).Height;
bmpout.Width := TBitmap(mylist[curidx]).Width;
bmpout.Assign(TBitmap(mylist[CurIdx]));
//sets zimage width height before getting image.
zimage1.Bitmap.Width := bmpout.Width;
zimage1.Bitmap.Height := bmpout.Height;
ZImage1.Bitmap.Assign(bmpout);
finally
BmpOut.Free;
end;
end;
page:= '0';
end;
如果你注意到我有这个部分,看看将 iamge 加载到 zimage1 中是否有问题。
//zimage1.Bitmap.Width := bmpout.Width;
//zimage1.Bitmap.Height := bmpout.Height;
//ZImage1.Bitmap.Assign(bmpout);
当我这样做时,它会将 bmpout 加载到 zimage1 中,这导致我认为它与我做错的对象列表有关?