| Version: 3.2.8

Public Member Functions | List of all members
wxImageList Class Reference
Class List by Category » Graphics Device Interface (GDI)

`#include <wx/imaglist.h>`

Inheritance diagram for wxImageList:
[legend]

## Detailed Description

A wxImageList contains a list of images, which are stored in an unspecified form.

Images can use alpha channel or 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.

Use of this class is not recommended in the new code as it doesn't support showing DPI-dependent bitmaps. Please use wxWithImages::SetImages() instead of wxWithImages::SetImageList().

##

Library: wxCore
Category: Graphics Device Interface (GDI)

See also
  wxTreeCtrl, wxListCtrl

## Public Member Functions
| wxImageList ()
| Default ctor. More...
| wxImageList (int width, int height, bool mask=true, int initialCount=1)
| Constructor specifying the image size, whether image masks should be created, and the initial size of the list. More...
int | Add (const wxBitmap &bitmap, const wxBitmap &mask=wxNullBitmap)
| Adds a new image or images using a bitmap and optional mask bitmap. More...
int | Add (const wxBitmap &bitmap, const wxColour &maskColour)
| Adds a new image or images using a bitmap and mask colour. More...
int | Add (const wxIcon &icon)
| Adds a new image using an icon. More...
bool | Create (int width, int height, bool mask=true, int initialCount=1)
| Initializes the list. More...
void | Destroy ()
| Destroys the current list. More...
virtual bool | Draw (int index, wxDC &dc, int x, int y, int flags=wxIMAGELIST_DRAW_NORMAL, bool solidBackground=false)
| Draws a specified image onto a device context. More...
wxBitmap | GetBitmap (int index) const
| Returns the bitmap corresponding to the given index. More...
wxIcon | GetIcon (int index) const
| Returns the icon corresponding to the given index. More...
virtual int | GetImageCount () const
| Returns the number of images in the list. More...
virtual bool | GetSize (int index, int &width, int &height) const
| Retrieves the size of the images in the list. More...
virtual wxSize | GetSize () const
| Retrieves the size of the image list as passed to Create(). More...
bool | Remove (int index)
| Removes the image at the given position. More...
bool | RemoveAll ()
| Removes all the images in the list. More...
bool | Replace (int index, const wxBitmap &bitmap, const wxBitmap &mask=wxNullBitmap)
| Replaces the existing image with the new image. More...
bool | Replace (int index, const wxIcon &icon)
| Replaces the existing image with the new image. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Additional Inherited Members
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ wxImageList() [1/2]

wxImageList::wxImageList | ( |  | ) |

Default ctor.

## ◆ wxImageList() [2/2]

wxImageList::wxImageList | ( | int | width,
|  | int | height,
|  | bool | mask = `true`,
|  | int | initialCount = `1`
| ) |  |

Constructor specifying the image size, whether image masks should be created, and the initial size of the list.

Note that the size is specified in logical pixels.

Parameters

  width | Width of the images in the list.
  height | Height of the images in the list.
  mask | If true, all images will have masks, with the mask being created from the light grey pixels if not specified otherwise, i.e. if the image doesn't have neither alpha channel nor mask and no mask is explicitly specified when adding it. Note that if an image does have alpha channel or mask, it will always be used, whether this parameter is true or false.
  initialCount | The initial size of the list.

See also
  Create()

## Member Function Documentation

## ◆ Add() [1/3]

int wxImageList::Add | ( | const wxBitmap & | bitmap,
|  | const wxBitmap & | mask = `wxNullBitmap`
| ) |  |

Adds a new image or images using a bitmap and optional mask bitmap.

The logical size of the bitmap should be the same as the size specified when constructing wxImageList. If the logical width of the bitmap is greater than the image list width, bitmap is split into smaller images of the required width.

Parameters

  bitmap | Bitmap representing the opaque areas of the image.
  mask | Monochrome mask bitmap, representing the transparent areas of the image.

Returns
  The new zero-based image index.

## ◆ Add() [2/3]

int wxImageList::Add | ( | const wxBitmap & | bitmap,
|  | const wxColour & | maskColour
| ) |  |

Adds a new image or images using a bitmap and mask colour.

The logical size of the bitmap should be the same as the size specified when constructing wxImageList. If the logical width of the bitmap is greater than the image list width, bitmap is split into smaller images of the required width.

Parameters

  bitmap | Bitmap representing the opaque areas of the image.
  maskColour | Colour indicating which parts of the image are transparent.

Returns
  The new zero-based image index.

## ◆ Add() [3/3]

int wxImageList::Add | ( | const wxIcon & | icon | ) |

Adds a new image using an icon.

The logical size of the icon should be the same as the size specified when constructing wxImageList.

Parameters

  icon | Icon to use as the image.

Returns
  The new zero-based image index.

Availability: only available for the wxMSW, wxOSX/Cocoa ports.

## ◆ Create()

bool wxImageList::Create | ( | int | width,
|  | int | height,
|  | bool | mask = `true`,
|  | int | initialCount = `1`
| ) |  |

Initializes the list.

See wxImageList() for details.

This function can be called only once after creating the object using its default ctor or after calling Destroy().

## ◆ Destroy()

void wxImageList::Destroy | ( |  | ) |

Destroys the current list.

This function resets the object to its initial state and does more than just RemoveAll() in the native wxMSW version.

After calling it, Create() may be called again to recreate the image list, e.g. using a different size.

Since
  3.1.6

## ◆ Draw()

virtual bool wxImageList::Draw | ( | int | index,
|  | wxDC & | dc,
|  | int | x,
|  | int | y,
|  | int | flags = `wxIMAGELIST_DRAW_NORMAL`,
|  | bool | solidBackground = `false`
| ) |  |
| virtual

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.

## ◆ GetBitmap()

wxBitmap wxImageList::GetBitmap | ( | int | index | ) | const

Returns the bitmap corresponding to the given index.

## ◆ GetIcon()

wxIcon wxImageList::GetIcon | ( | int | index | ) | const

Returns the icon corresponding to the given index.

## ◆ GetImageCount()

virtual int wxImageList::GetImageCount | ( |  | ) | const
| virtual

Returns the number of images in the list.

## ◆ GetSize() [1/2]

virtual wxSize wxImageList::GetSize | ( |  | ) | const
| virtual

Retrieves the size of the image list as passed to Create().

Returns
  the size of the image list, which may be zero if the image list was not yet initialised.

## ◆ GetSize() [2/2]

virtual bool wxImageList::GetSize | ( | int | index,
|  | int & | width,
|  | int & | height
| ) |  | const
| virtual

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

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

## ◆ Remove()

bool wxImageList::Remove | ( | int | index | ) |

Removes the image at the given position.

## ◆ RemoveAll()

bool wxImageList::RemoveAll | ( |  | ) |

Removes all the images in the list.

## ◆ Replace() [1/2]

bool wxImageList::Replace | ( | int | index,
|  | const wxBitmap & | bitmap,
|  | const wxBitmap & | mask = `wxNullBitmap`
| ) |  |

Replaces the existing image with the new image.

Parameters

  index | The index of the bitmap to be replaced.
  bitmap | Bitmap representing the opaque areas of the image.
  mask | Monochrome mask bitmap, representing the transparent areas of the image.

Returns
  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.

## ◆ Replace() [2/2]

bool wxImageList::Replace | ( | int | index,
|  | const wxIcon & | icon
| ) |  |

Replaces the existing image with the new image.

Parameters

  index | The index of the bitmap to be replaced.
  icon | Icon to use as the image.

Returns
  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.

Availability: only available for the wxMSW, wxOSX/Cocoa ports.