Title: Save (and Load) all the Images from a Delphi TImageList to a Single File
The WriteComponentResFile Delphi function can be used to store components and their properties to a single file using a resource file format.
Saving Images in a TImageList into a Single File
If you have a TImageList control populated with images, each of the (same sized) images can be accessed using the index of the image.
Images stored in a TImageList are used for different Delphi components like: Menus, TreeViews, ListViewes etc.
If you want to reuse images from a the TImageList control, you can populate the TImageList with images, store all the images in a single resource-like file, then reuse at run time, by dynamically restoring the TImageList control from the saved file.
WriteComponentResFile
To save an instance of a Delphi component and its properties to a file, use the WriteComponentResFile method:
WriteComponentResFile('ImageList.dat', ImageList1) ;
The ImageList1 is the name of the TIMageList component droped on a form and populated with images.
ReadComponentResFile
To read the component and its properties from a file, use the ReadComponentResFile function.
Suppose there were 4 images in the ImageList1 we saved to a file. To restore the image list with its images programmatically, and display the 4 images in 4 TImage controls, you can use the following code:
var
imageList : TImageList;
begin
imageList := TImageList.Create(nil) ;
try
ReadComponentResFile('ImageList.dat', imageList) ;
imageList.GetBitmap(0,Image1.Picture.Bitmap) ;
imageList.GetBitmap(1,Image2.Picture.Bitmap) ;
imageList.GetBitmap(2,Image3.Picture.Bitmap) ;
imageList.GetBitmap(3,Image4.Picture.Bitmap) ;
finally
FreeAndNil(imageList) ;
end;
end;