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
#Initializes a new instance of the Palette class with the specified colors
Parameters:
| colors (IEnumerable<Color>) | Initial colors to add to the palette |
Properties
Methods
AddRange
#Adds the specified
colors to this palette collectionParameters:
| colors (IEnumerable<Color>) | Colors to add to this palette collection |
ClearItems
#protected override void ClearItems()
Called when clearing the items, to clear the cached argb values
Clone
#Creates a clone of this palette
Returns: A new instance of a palette with the same color entries as this instance
Equals
#Gets a value indicating that this object is equal to the specified
objParameters:
| obj (object) | Object to compare for equality |
Returns: True if the specified obj is a Palette and contains the same colors as this instance, false otherwise
Overrides: Object.Equals
FindAddColour
#Finds the index of the specified color, or adds it if it does not exist
Parameters:
| color (Color) | Color to find/add |
Returns: 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
#Finds the closest color in this palette to the specified
colorParameters:
| color (Color) | Color to use to find the closest color |
Returns: Index of the closest entry of the specified
colorFromEGA
#Gets the standard 16 colors of the specified EGA palette, at the indexes specified with EGAColors
GetDosPalette
#Gets the standard 16-color palette used in DOS
Returns: A new instance of a Palette with the standard 16 DOS colors
GetEgaPalette
#Gets the standard 64-color EGA palette
Remarks: To get the standard 16-colors of an EGA palette, use FromEGA(Palette)
GetHashCode
#Gets the hash code for this palette
Returns: Hash code of this palette
Overrides: Object.GetHashCode
GetRGBColor
#Gets the cached ARGB value of the color at the specified
indexParameters:
| index (int) | Index to get the ARGB color for |
Returns: A 32-bit ARGB color value of the color at the specified index
InsertItem
#Called when inserting a color, to insert the cached argb value of the color
Overrides: ObservableCollection<1>.InsertItem
Load
#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.Parameters:
| 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 |
Save
#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.Parameters:
| 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
#Called when setting a color in the palette, to set the cached argb value of the color
Overrides: ObservableCollection<1>.SetItem
Creates a clone of this palette
Returns: A new instance of a palette with the same color entries as this instance