正如我在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