ColorPalette type

A palette of up to 256 colours for a bitmap with an indexed pixel format.

An indexed bitmap stores, for each pixel, the number of an entry of its palette instead of a colour. A ColorPalette holds such a palette, and goes to Bitmap.ConvertFormat and ImageAttributes.GetAdjustedPalette. The type mirrors the GDI+ ColorPalette structure, with room for 256 entries always.

Fields

Field Type Meaning
flags PaletteFlags Whether the palette has alpha values, is a grayscale or is a halftone palette.
count Long The number of entries that are in use.
entries Long array, 0 to 255 The colours, each as &HAARRGGBB.

Creating

Syntax: pal = ColorPalette( flags, entries( ) )

flags
required A PaletteFlags value for flags.
entries
required An array of Long colours, &HAARRGGBB.

The function sets flags and sets count to the smaller of 256 and the length of entries.

Dim user As GdiPlusUser = GdiPlusUser()

Dim colours(0 To 1) As Long
colours(0) = &HFF000000
colours(1) = &HFFFFFFFF

Dim made As ColorPalette = ColorPalette(PaletteFlagsGrayScale, colours)
Debug.Print made.count & " " & Hex$(made.entries(1))        ' the colours are not there

Dim pal As ColorPalette
pal.flags = PaletteFlagsGrayScale
pal.count = 2
pal.entries(0) = colours(0)
pal.entries(1) = colours(1)
Debug.Print pal.count & " " & Hex$(pal.entries(1))
' Output:
' 2 0
' 2 FFFFFFFF

See Also