Save Image List in Delphi

Source: Internet
Author: User

A recent project was encountered when a series of images in an image list (timagelist) were saved to a specified file or binary stream for dynamic recovery when needed.

So in Delphi help find Timagelist Class related properties, methods, unfortunately, Delphi in Timagelist did not provide SaveToFile and Savetostream method, so the current restrictions on timagelist, There must be other ways to extend the functionality of the timagelist to meet the needs of the actual project.

Solving method

Method One:

Use API functions Imagelist_write and Imagelist_read. Both need to specify a parameter of type IStream, the former is to save the image list of the specified handle to a binary stream of type IStream, which reads the previously saved list of images from a binary stream of type IStream and returns a handle to the list of images. IStream is an OLE object that is declared in Delphi as Tstreamadapter = Class (Tinterfacedobject, IStream), Tstreamadapter is the object of manipulating the IStream interface inherited from Tinterfacedobject. Through the Tstreamadapter object, Delphi internal Tstream object can be manipulated to IStream interface object.

Method Two:

Inherits a subclass Timagelistex from Timagelist, implementing a custom Savetofileex and Savetostreamex method. The image saved in Timagelist by default is a combination of a normal image and its mask image, so the GetImages (Index:integer) provided by the protected portion of its base class tcustomimagelist must be invoked; Image, Mask:tbitmap) method to obtain a bitmap of the specified index number in the image list and its mask bitmap, which is then saved to the custom file or binary stream, respectively, You also need to provide Loadfromfileex and Loadfromstreamex methods to recover the collection of images from a custom file or binary stream.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.