正如我在coment中所提到的,您可以创建一个TJPEGImage对象数组存储图像。
你这样做,像这样:
//Global array for storing images
var Images: Array [1..26] of TJPEGImage;
implemenetation
...
procedure TForm1.FormCreate(Sender: TObject);
var I: Integer;
begin
for I := 1 to 26 do
begin
//Since TJPEGIMage is a class we first need to create each one as array only
//stores pointer to TJPEGImage object and not the object itself
Images[I] := TJPEGImage.Create;
//Then we load Image data from file into each TJPEGImage object
//If file names are not numerically ordered you would probably load images
//later and not inside this loop. This depends on your design
Images[I].LoadFromFile('D:\Image'+IntToStr(I)+'.jpg');
end;
end;
正如您在源看到评析阵列只存储指针TJPEGImage对象,而不是TJPEGImage对象自理。因此,在尝试将任何图像数据加载到它们之前,请不要忘记创建它们。如果不这样做将导致访问冲突。
而且becouse您自行创建这些TJPEGImage对象,你还需要自己解放出来,以避免更多钞票内存泄漏
procedure TForm1.FormDestroy(Sender: TObject);
var I: Integer;
begin
for I := 1 to 26 do
begin
Images[I].Free;
end;
end;
为了显示你的TImage组件使用该
这些存储的图像
//N is array index number telling us which array item stores the desired image
Image1.Picture.Assign(Images[N]);
,您可以使用
现在既然TJPEGImage是类第二条本办法编辑对象,你也可以使用TObjectList来存储指向它们的指针。 在这种情况下创建的代码应该是这样的
procedure TForm1.FormCreate(Sender: TObject);
var I: Integer;
Image: TJPEGImage;
for I := 1 to NumberOfImages do
begin
//Create TObject list with AOwnsObjects set to True means that destroying
//the object list will also destroy all of the objects it contains
//NOTE: On ARC compiler destroying TObjectList will only remove the reference
//to the objects and they will be destroyed only if thir reference count
//drops to 0
Images := TObjectList.Create(True);
//Create a new TJPEGImage object
Image := TJPEGImage.Create;
//Load image data into it from file
Image.LoadFromFile('Image'+IntToStr(I)+'.jpg');
//Add image object to our TObject list to store reference to it for further use
Images.Add(Image);
end;
end;
您现在会显示这些图像,像这样
//Note becouse first item in TObject list has index of 0 you need to substract 1
//from your ImageNumber
Image1.Picture.Assign(TJPEGImage(Images[ImageNumber-1]));
由于我们设定TObjectList拥有我们TJPEGImage对象,我们可以很快将其消灭所有的人都像这样
//NOTE: On ARC compiler destroying TObjectList will only remove the reference
//to the objects and they will be destroyed only if thir reference count
//drops to 0
Images.Free;
关于数据库部分[保存和加载JPEG图像数据库....(http://stackoverflow.com/questions/18214686/saving-and-loading-jpeg-images-to-database-不工作的delphi) – bummi 2014-09-26 06:42:55
我不确定你应该在这种情况下使用'TImageList'来存储(高分辨率?)图像(不是图标)。改为创建并使用通用的'TObjectList'。 –
teran
2014-09-26 09:28:44
为什么你不要在每个TJpegImage中创建和存储TJpegImage数组并存储单个图像。 – SilverWarior 2014-09-26 10:43:48