Represents a collection of Color objects
Remarks: Typically used for IndexedBitmap or other purposes where a collection of colors is needed. This class keeps a cache of 32-bit ARGB values for each element in the collection for faster retrieval. These values are generated using Color.ToArgb().

Constructors

Palette

#
public Palette()
Initializes a new instance of the Pallette class

Palette

#
public Palette(IEnumerable<Color> colors)
Initializes a new instance of the Palette class with the specified colors

Properties

EGAColors

#
public static int[] EGAColors { get; }
Gets the index of standard EGA colors from a 64-color palette

Methods

AddRange

#
public void AddRange(IEnumerable<Color> colors)
Adds the specified colors to this palette collection

ClearItems

#
protected override void ClearItems()
Called when clearing the items, to clear the cached argb values

Clone

#
public Palette Clone()
Creates a clone of this palette
A new instance of a palette with the same color entries as this instance

Equals

#
public override bool Equals(object obj)
Gets a value indicating that this object is equal to the specified obj
obj (object)Object to compare for equality
True if the specified obj is a Palette and contains the same colors as this instance, false otherwise
Object.Equals

FindAddColour

#
public int FindAddColour(Color color)
Finds the index of the specified color, or adds it if it does not exist
color (Color)Color to find/add
Index of the existing entry in this palette that matches the specified color, or the index of the newly added entry if not found

FindClosest

#
public int FindClosest(Color color)
Finds the closest color in this palette to the specified color
color (Color)Color to use to find the closest color
Index of the closest entry of the specified color

FromEGA

#
public static Palette FromEGA(Palette palEGA)
Gets the standard 16 colors of the specified EGA palette, at the indexes specified with EGAColors
palEGA (Palette)EGA palette to get the standard 16 colors from
A new instance of a palette with the 16 colors at the indexes specified with EGAColors

GetDosPalette

#
public static Palette GetDosPalette()
Gets the standard 16-color palette used in DOS

GetEgaPalette

#
public static Palette GetEgaPalette()
Gets the standard 64-color EGA palette

GetHashCode

#
public override int GetHashCode()
Gets the hash code for this palette

GetRGBColor

#
public int GetRGBColor(int index)
Gets the cached ARGB value of the color at the specified index
index (int)Index to get the ARGB color for
A 32-bit ARGB color value of the color at the specified index

InsertItem

#
protected override void InsertItem(int index, Color item)
Called when inserting a color, to insert the cached argb value of the color

Load

#
public void Load(BinaryReader reader, int size, int shift = 0, bool includeAlpha = false)
Loads the palette from the specified binary reader in (A)RGB components
Remarks: Each component is read as a single byte (regardless of the value of shift). It is read in the order of Alpha (if includeAlpha is true), Red, Green, then Blue.
reader (BinaryReader)Reader to read the data from
size (int)Number of palette entried to load
shift (int = 0)Shift amount for each component. 0 = 0-255, 1 = 0-128, 2 = 0-64, etc
includeAlpha (bool = false)True to include the alpha component, false to only read RGB components

RemoveItem

#
protected override void RemoveItem(int index)
Called when removing an item, to remove the cached argb value of the color

Save

#
public void Save(BinaryWriter writer, int shift = 0, bool includeAlpha = false)
Saves this palette to the specified binary writer in (A)RGB components
Remarks: Each component is saved as a single byte (regardless of the value of shift). It is saved in the order of Alpha (if includeAlpha is true), Red, Green, then Blue.
writer (BinaryWriter)Writer to write the data to
shift (int = 0)Shift amount for each component. 0 = 0-255, 1 = 0-128, 2 = 0-64, etc
includeAlpha (bool = false)True to include alpha, false to only include RGB components

SetItem

#
protected override void SetItem(int index, Color item)
Called when setting a color in the palette, to set the cached argb value of the color
Explicit

ICloneable.Clone

#Since v2.10
Creates a clone of this palette
A new instance of a palette with the same color entries as this instance