## wxPalette

A palette is a table that maps pixel values to RGB colours. It allows the colours of a low-depth bitmap, for example, to be mapped to the available colours in a display. The notion of palettes is becoming more and more obsolete nowadays and only the MSW port is still using a native palette. All other ports use generic code which is basically just an array of colours.

It is likely that in the future the only use for palettes within wxWidgets will be for representing colour indeces from images (such as GIF or PNG). The image handlers for these formats have been modified to create a palette if there is such information in the original image file (usually 256 or less colour images). See wxImage for more information.

Derived from

wxGDIObject
wxObject

Include files

<wx/palette.h>

Predefined objects

Objects:

wxNullPalette

See also

wxDC::SetPalette, wxBitmap

Members

wxPalette::wxPalette
wxPalette::~wxPalette
wxPalette::Create
wxPalette::GetColoursCount
wxPalette::GetPixel
wxPalette::GetRGB
wxPalette::IsOk
wxPalette::operator =

### wxPalette::wxPalette

wxPalette()

Default constructor.

wxPalette(const wxPalette& palette)

Copy constructor, uses reference counting.

wxPalette(int n, const unsigned char* red,
const unsigned char* green, const unsigned char* blue)

Creates a palette from arrays of size n, one for each red, blue or green component.

Parameters

palette

A pointer or reference to the palette to copy.

n

The number of indices in the palette.

red

An array of red values.

green

An array of green values.

blue

An array of blue values.

See also

wxPalette::Create

### wxPalette::~wxPalette

~wxPalette()

Destructor. See reference-counted object destruction for more info.

### wxPalette::Create

bool Create(int n, const unsigned char* red, const unsigned char* green, const unsigned char* blue)

Creates a palette from arrays of size n, one for each red, blue or green component.

Parameters

n

The number of indices in the palette.

red

An array of red values.

green

An array of green values.

blue

An array of blue values.

Return value

true if the creation was successful, false otherwise.

See also

wxPalette::wxPalette

### wxPalette::GetColoursCount

int GetColoursCount() const

Returns number of entries in palette.

### wxPalette::GetPixel

int GetPixel(unsigned char red, unsigned char green, unsigned char blue) const

Returns a pixel value (index into the palette) for the given RGB values.

Parameters

red

Red value.

green

Green value.

blue

Blue value.

Return value

The nearest palette index or `wxNOT_FOUND` for unexpected errors.

See also

wxPalette::GetRGB

### wxPalette::GetRGB

bool GetRGB(int pixel, const unsigned char* red, const unsigned char* green, const unsigned char* blue) const

Returns RGB values for a given palette index.

Parameters

pixel

The palette index.

red

Receives the red value.

green

Receives the green value.

blue

Receives the blue value.

Return value

true if the operation was successful.

See also

wxPalette::GetPixel

### wxPalette::IsOk

bool IsOk() const

Returns true if palette data is present.

### wxPalette::operator =

wxPalette& operator =(const wxPalette& palette)

Assignment operator, using reference counting.