wxImageList

A wxImageList contains a list of images, which are stored in an unspecified form. Images can have masks for transparent drawing, and can be made from a variety of sources including bitmaps and icons.
wxImageList is used principally in conjunction with wxTreeCtrl and wxListCtrl classes.

Derived from

wxObject

Include files

<wx/imaglist.h>

See also

wxTreeCtrl, wxListCtrl

Members


wxImageList::wxImageList

wxImageList()
Default constructor.
wxImageList(int width, int height, const bool mask = true, int initialCount = 1)
Constructor specifying the image size, whether image masks should be created, and the initial size of the list.

Parameters

width
Width of the images in the list.
height
Height of the images in the list.
mask
true if masks should be created for all images.
initialCount
The initial size of the list.

See also

wxImageList::Create

wxImageList::Add

int Add(const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap)
Adds a new image or images using a bitmap and optional mask bitmap.
int Add(const wxBitmap& bitmap, const wxColour& maskColour)
Adds a new image or images using a bitmap and mask colour.
int Add(const wxIcon& icon)
Adds a new image using an icon.

Parameters

bitmap
Bitmap representing the opaque areas of the image.
mask
Monochrome mask bitmap, representing the transparent areas of the image.
maskColour
Colour indicating which parts of the image are transparent.
icon
Icon to use as the image.

Return value

The new zero-based image index.

Remarks

The original bitmap or icon is not affected by the Add operation, and can be deleted afterwards.
If the bitmap is wider than the images in the list, then the bitmap will automatically be split into smaller images, each matching the dimensions of the image list. This does not apply when adding icons.
wxPython note: In place of a single overloaded method name, wxPython implements the following methods:
Add(bitmap, mask=wxNullBitmap)
AddWithColourMask(bitmap, colour)
AddIcon(icon)

wxImageList::Create

bool Create(int width, int height, const bool mask = true, int initialCount = 1)
Initializes the list. See wxImageList::wxImageList for details.

wxImageList::Draw

bool Draw(int index, wxDC& dc, int x, int y, int flags = wxIMAGELIST_DRAW_NORMAL, const bool solidBackground = false)
Draws a specified image onto a device context.

Parameters

index
Image index, starting from zero.
dc
Device context to draw on.
x
X position on the device context.
y
Y position on the device context.
flags
How to draw the image. A bitlist of a selection of the following:
wxIMAGELIST_DRAW_NORMAL
Draw the image normally.
wxIMAGELIST_DRAW_TRANSPARENT
Draw the image with transparency.
wxIMAGELIST_DRAW_SELECTED
Draw the image in selected state.
wxIMAGELIST_DRAW_FOCUSED
Draw the image in a focused state.
solidBackground
For optimisation - drawing can be faster if the function is told that the background is solid.

wxImageList::GetBitmap

wxBitmap GetBitmap(int index) const
Returns the bitmap corresponding to the given index.

wxImageList::GetIcon

wxIcon GetIcon(int index) const
Returns the icon corresponding to the given index.

wxImageList::GetImageCount

int GetImageCount() const
Returns the number of images in the list.

wxImageList::GetSize

bool GetSize(int index, int& width, int & height) const
Retrieves the size of the images in the list. Currently, the index parameter is ignored as all images in the list have the same size.

Parameters

index
currently unused, should be 0
width
receives the width of the images in the list
height
receives the height of the images in the list

Return value

true if the function succeeded, false if it failed (for example, if the image list was not yet initialized).

wxImageList::Remove

bool Remove(int index)
Removes the image at the given position.

wxImageList::RemoveAll

bool RemoveAll()
Removes all the images in the list.

wxImageList::Replace

bool Replace(int index, const wxBitmap& bitmap, const wxBitmap& mask = wxNullBitmap)
Replaces the existing image with the new image.
Windows only.
bool Replace(int index, const wxIcon& icon)
Replaces the existing image with the new image.

Parameters

bitmap
Bitmap representing the opaque areas of the image.
mask
Monochrome mask bitmap, representing the transparent areas of the image.
icon
Icon to use as the image.

Return value

true if the replacement was successful, false otherwise.

Remarks

The original bitmap or icon is not affected by the Replace operation, and can be deleted afterwards.
wxPython note: The second form is called ReplaceIcon in wxPython.