Sign in Join
FPDoc Onlineexperiment

TCustomImageList class

In unit ImgList

The base class for TImageList.

Declaration

pascal
TCustomImageList = class(TLCLComponent)

Inheritance

  1. TCustomImageList
  2. TLCLComponent
  3. TComponent
  4. TPersistent
  5. TObject

Descends from it: TDragImageList TLCLGlyphs

Description

TCustomImageList is a TLCLComponent descendant that implements the base class for TImageList. Image lists are used to provide images, icons, and overlays in controls like TMenu, TToolBar, TCoolBar, TActionList, TComboEx, TTabControl, TDBNav, TListView, TTreeView, and others.

Historically, TCustomImageList was based on the Win32 image list implemented in Delphi. Internally, the image list contained images (bitmaps or icons) of the same Width and Height. The images were stored in one big bitmap, whose total width was Width * Count pixels. This reduced the number of handles allocated when images in the image list were accessed.

Starting with LCL version 1.9, the concept of multiple image resolutions (or sizes) was introduced in TCustomImageList. This allowed the image list to contain multiple sizes for a given image. Multiple resolutions are implemented as parallel image lists, with images of the same size stored in a single image list. Image scaling was also introduced in TCustomImageList using its new support classes, and allowed resizing of images for high PPI (pixels per inch) displays.

Images stored in TCustomImageList are represented using 32-bit RGBA (Red Green Blue Alpha) raw image data. Transparency is implemented using the Alpha channel in the raw image data, but not all platforms/widgetsets support an 8-bit Alpha channel. Any image type descended from TCustomBitmap can be added to an image list, including:

  • TBitmap
  • TIcon
  • TPortableNetworkGraphic
  • TPortableAnyMapGraphic
  • TJpegImage
  • TGIFImage
  • TTiffImage
  • TPixMap
Starting with Lazarus 2.2, binary bitmap data stored for the image list in an LFM file uses ZLib compression. While this makes both the LFM and the EXE smaller, it also prevents Lazarus versions prior to 2.0 from opening the LFM file. If you need to maintain a Version 2.X project in an older Lazarus version, you first have to open it in Lazarus 2.0 and resave any forms with a TImageList. Then you can open these resaved LFMs in Lazarus versions prior to 2.0.

Use the Width and Height properties to set the default resolution (or size) used for images in the image list. If an image with a size different than the values in Width and Height is added to the default resolution, it is scaled the dimensions required for the resolution. The Width and Height properties also establish the image size used at the 100% scaling level on a 96 PPI display.

Changing the value in the Width or Height properties causes the image list and all of its resolutions to be cleared. Set the values in Width and Height prior to adding images to the default resolution.

TCustomImageList implements an internal container for each Resolution (or size) supported in the image list. This TCustomImageListResolutions class instance maintains separate parallel image lists where each list contains images for a given height and width.

Use the Resolutions or ResolutionsDesc methods to access enumerators (ascending and descending respectively) for the image resolutions stored in the container.

Each image Resolution (or size) is represented using a TCustomImageListResolution class instance. Like previous versions of TCustomImageList, it provides properties and methods needed to access and maintain images using a common height and width. It also provides access to the 32-bit RGBA raw image data for images in the resolution. The Draw, StretchDraw, and DrawOverlay methods are provided to render an image to a TCanvas instance.

Use the indexed Resolution property to access the image list with a specific image width. Use ResolutionByIndex to get an image resolution using its position in the image resolutions container. Use ResolutionForPPI to get a dynamically scaled image resolution using a specific image width, display density, and scaling factor.

The FindResolution method can be used to locate the image list which uses a specific image width. Use the RegisterResolutions method to pre-define the image sizes supported in the image list.

Use the Scaled property to indicate if images are automatically scaled to a Resolution not stored in the image list. Setting Scaled to True enables the automatic scaling features in TCustomImageList, and allows images to be scaled for use on high PPI displays. When an image list is selected using the Resolution property, or by calling GetResolutionForPPI, images will automatically be scaled from a suitable candidate resolution to the requested value. Set Scaled to False to use the closest image size in the list. Use the OnGetWidthForPPI event handler to perform image size substitution based on pixel display density.

Use the Masked property to determine if images in the list have a mask applied to define the transparent areas in images. Use the Add method to store an image with the combined values from its source data and optional mask. Use AddMasked to store an image using MaskColor to represent its transparent areas. Use AddMultipleResolutions to scale and store an array of bitmaps to each of the Resolutions defined for the image list. Use AddSlice and AddSliced to store one or many images using the native image list storage format. Use ImageType to indicate whether the image list contains images or image masks.

Please note that inserting or moving images will affect the index position for all following images in the resolution, and may cause problems when constant index positions are expected. In such cases a bitmap collection may better fit your needs.

Due to its use of multiple resolutions and dynamic scaling, TCustomImageList is not suitable for use as a generic TBitmap collection. If fast storage of bitmaps is needed, you can create your own container using an array or TList class instance.

Multiple image resolutions, and scaling were added in LCL version 1.9.

See also

Properties

HasOverlayspublicIndicates if any images in the list have been used as an overlay image.
AllocBypublicSize used to increment the allocated data count.
BlendColorpublicColor used when blending (dithering) an image.
BkColorpublicSpecifies the background color used for transparent parts of images.
CountpublicNumber of images stored in the default resolution for the image list.
DrawingStylepublicThe default drawing style for images in the image list.
HandlepublicContains the handle for the default image resolution in the image list.
HeightpublicHeight of images in the default resolution for the image list.
HeightForPPIpublicHeight for images at the specified display density.
HeightForWidthpublicHeight used for images with the width specified width.
WidthpublicWidth of images in the default resolution for the image list.
WidthForPPIpublicImage width needed for the specified display density (PPI).
SizeForPPIpublicSize used for images with the specified image width at the given display density.
MaskedpublicIndicates if an image mask is used for images in the list.
ReferencepublicProvides access to the reference class for the specified resolution.
ReferenceForPPIpublicReference class using the specified image width and display density.
ResolutionpublicProvides indexed access to an image resolution with the specified image width.
ResolutionByIndexpublicProvides access to an image resolution by its ordinal position in the image list.
ResolutionForPPIpublicGets a scaled resolution with the specified width, display density, and scaling factor.
ResolutionCountpublicNumber of image resolutions available in the image list.
OverlayspublicProvides access to images used as overlays in the image list.
ScaledpublicControls whether image sizes are automatically scaled for different display density (Pixels per Inch) settings.
ShareImagespublicTrue when the handle for the image list is shared.
ImageTypepublicControls whether images are drawn with or without a mask.

Methods

GetResolutionprotectedGets the value for the indexed Resolution property.
GetResolutionClassprotectedGets the class type used to create image resolutions in the list.
CheckIndexprotectedEnsures that an Index position is valid for the bounds of the image list.
InitializeprotectedPerforms the initial set up for the image list.
DefinePropertiesprotectedDefines properties used in the LCL component streaming mechanism.
SetWidthHeightprotectedSets the Width and Height for images in the default resolution.
ClearOverlaysprotectedClears images indexes assigned as overlay images in the image list.
MarkAsChangedprotectedSets the value in the internal Changed flag to True.
DoAfterUpdateStartedprotectedPerforms actions needed after the BeginUpdate method is started.
DoBeforeUpdateEndedprotectedPerforms actions needed before the EndUpdate method is completed.
CreatepublicConstructor for the class instance.
CreateSizepublicInitializes the image list using the specified height and width.
DestroypublicDestructor for the class instance.
ScaleImagepublicScales an image and its optional mask to the specified target size.
AssignTopublicAssigns properties in an image list to another instance of the class.
AssignpublicStores properties from the specified image list to the current class instance.
WriteDatapublicWrites image data for the default resolution to a stream.
ReadDatapublicReads image data for the default resolution from a stream.
WriteAdvDatapublicWrites the image content for multiple resolutions to the specified stream.
ReadAdvDatapublicReads the image content for multiple resolutions from a stream.
EqualspublicCompares the contents of the image lists.
BeginUpdatepublicStarts an update to the image list, and controls execution of the OnChange event.
EndUpdatepublicFinishes an update to the image list, and calls Change.
AddpublicAdds an image to the list using its source data and optional mask.
AddMultipleResolutionspublicAdds images with varying sizes to the corresponding image resolution.
AddSlicedpublicAdds images to the image list from image data stored as adjacent columns and rows.
AddSlicepublicAdds a portion of an image to each of the resolutions in the image list.
AddSliceCenteredpublicAdds an image centered in the height and width for the image resolutions.
AddIconpublicAdds an icon to the image list.
AddImagespublicAdds images from another image list to the current class instance.
AddMaskedpublicAdds an image(s) to the list using the MaskColor for transparent pixels.
AddLazarusResourcepublicGets a bitmap from a Lazarus resource and stores it in the image list.
AddResourceNamepublicAdds a graphic from a resource with the specified resource name.
ChangepublicSends change notifications when the image list is updated.
ClearpublicRemoves all images store in the image list.
DeletepublicDeletes the image at the specified position from all image resolutions.
DrawpublicRenders an image to the specified canvas using a drawing style or effect.
DrawForPPIpublicRenders an image to a canvas scaled to a specified display density.
DrawOverlaypublicRenders an image with an overlay to the specified canvas.
GetBitmappublicGets image data at the specified position as a bitmap.
GetFullBitmappublicGets a bitmap with all of the images in the default resolution.
GetFullRawImagepublicGets the raw image data for all images in the default resolution.
GetIconpublicGets the icon at the specified index and applies an image effect.
GetRawImagepublicGets the raw image data at the specified position from the default image resolution (Width).
GetHotSpotpublicReturns the offset from the drawing position to the image origin.
InsertpublicInserts an image into each image resolution at the specified position.
InsertIconpublicInserts an Icon into each of the resolutions for the image list.
InsertMaskedpublicInserts a transparent image into the image resolutions at the specified position.
MovepublicMoves an image from the position at CurIndex to NewIndex.
OverlaypublicAssigns the specified image to the given overlay position for the image list.
ReplacepublicReplaces an image at the specified position with the given bitmap.
ReplaceSlicepublicReplace an image at the specified position with a slice from the specified image.
ReplaceSliceCenteredpublicReplaces the image at the specified position from image data stored as adjacent columns and rows.
ReplaceIconpublicReplaces the icon at the specified position in all resolutions for the image list.
ReplaceMaskedpublicReplaces the image at the specified position with a masked image.
RegisterChangespublicRegisters a TChangeLink object for notifications when the image list is changed.
StretchDrawpublicDraws an image stretched to the dimensions for the target rectangle.
UnRegisterChangespublicUnregisters a ChangeLink object for change notifications.
RegisterResolutionspublicRegisters image resolutions (sizes) to use in the image list.
DeleteResolutionpublicDeletes the image resolution which uses the specified image width.
FindResolutionpublicFinds the image resolution which uses the specified image width.
SetSizepublic
ResolutionspublicProvides access to the image resolutions (or sizes) used in the image lists.
ResolutionsDescpublicProvides access to the descending enumerator for image resolutions in the list.

Events

OnChangepublicEvent handler signalled when one or more of the images in the image list has been changed.
OnGetWidthForPPIpublicEvent handler used to override the scaled width for a display density.

Inherited

From TLCLComponent (8)

DecLCLRefCount GetWSComponentClass IncLCLRefCount LCLRefCount NewInstance RemoveAllHandlersOfObject WidgetSetClass WSRegisterClass

From TComponent (73)

_AddRef _Release BeforeDestruction CanObserve ChangeName ComObject ComponentCount ComponentIndex Components ComponentState ComponentStyle DesignInfo DestroyComponents Destroying ExecuteAction FindComponent FreeNotification FreeOnRelease GetChildOwner GetChildParent GetChildren GetDeltaStreams GetEnumerator GetIDsOfNames GetNamePath GetObservers GetOwner GetParentComponent GetTypeInfo GetTypeInfoCount HasParent iicrGetComponent InsertComponent Invoke IsImplementorOf Loaded Loading Name Notification ObserverAdded Observers OnGetDeltaStreams Owner PaletteCreated QueryInterface ReadDeltaState ReadDeltaStream ReadState ReferenceInterface RemoveComponent RemoveFreeNotification RemoveFreeNotifications SafeCallException SetAncestor SetChildOrder SetDesigning SetDesignInstance SetInline SetName SetParentComponent SetSubComponent Tag ToString TToStringNameMode UpdateAction Updated UpdateRegistry Updating ValidateContainer ValidateInsert ValidateRename VCLComObject WriteState

From TPersistent (3)

FPOAttachObserver FPODetachObserver FPONotifyObservers

From TObject (35)

AfterConstruction CheckDisposed ClassInfo ClassName ClassNameIs ClassParent ClassType CleanupInstance DefaultHandler DefaultHandlerStr Dispatch DispatchStr Disposed DisposeOf FieldAddress Free FreeInstance GetDisposed GetHashCode GetInterface GetInterfaceByStr GetInterfaceEntry GetInterfaceEntryByStr GetInterfaceTable GetInterfaceWeak GetLastCastErrorInfo InheritsFrom InitInstance InstanceSize MethodAddress MethodName QualifiedClassName StringMessageTable SystemHasExtendedRTTI UnitName

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.