ImagePalette Class
An immutable palette of 1 to 256 colors with 8-bit samples and straight alpha, for a color reduction (QuantizeOptions.Palette). Build one from the pixels of frames with PaletteBuilder, or list the colors.
public sealed class ImagePalette : IEnumerable<Rgba32>, IReadOnlyCollection<Rgba32>, IReadOnlyList<Rgba32>, IEnumerableRemarks
The colors keep their order, without duplicates (the first occurrence is kept). Every fully transparent color is the same entry, transparent black: the color hidden by a transparent pixel is not part of a palette.
When it maps a color, a reduction compares an opaque pixel with the opaque entries only (a palette without opaque entry excepted), so opaque areas never become translucent; a translucent pixel is compared with every entry. The encoders restrict the entries to what their format stores: see GifEncoder.Quantization, BmpEncoder.Quantization and PngEncoder.Quantization.
Constructors
| Name | Description |
|---|---|
| ImagePalette(IEnumerable<Rgba32>) | Initializes a new instance of the ImagePalette class. |
| ImagePalette(ReadOnlySpan<Rgba32>) | Initializes a new instance of the ImagePalette class. |
ImagePalette overloads
ImagePalette(IEnumerable<Rgba32>)
ImagePalette.csInitializes a new instance of the ImagePalette class.
public ImagePalette(IEnumerable<Rgba32> colors)Parameters
colorsIEnumerable<Rgba32>- The colors.
Exceptions
ArgumentNullExceptioncolorsisnull.ArgumentExceptioncolorshas no color, or more than 256 distinct colors.
ImagePalette(ReadOnlySpan<Rgba32>)
ImagePalette.csInitializes a new instance of the ImagePalette class.
public ImagePalette(ReadOnlySpan<Rgba32> colors)Parameters
colorsReadOnlySpan<Rgba32>- The colors.
Exceptions
ArgumentExceptioncolorshas no color, or more than 256 distinct colors.
Properties
| Name | Description |
|---|---|
| Colors | Gets the colors, in palette order. |
| Count | Gets the number of colors. |
| HasTransparentColor | Gets a value indicating whether the palette has a fully transparent entry. |
Colors
ImagePalette.csCount
ImagePalette.csHasTransparentColor
ImagePalette.csIndexers
| Name | Description |
|---|---|
| this[int] | Gets a color. |
this[int]
ImagePalette.csGets a color.
Parameters
indexint- The index of the color.
Property value
Exceptions
ArgumentOutOfRangeExceptionindexis negative or not less thanImagePalette.Count.
Methods
| Name | Description |
|---|---|
| GetEnumerator() | Returns an enumerator over the colors, in palette order. |
| System.Collections.IEnumerable.GetEnumerator() |
GetEnumerator()
ImagePalette.csReturns an enumerator over the colors, in palette order.
public IEnumerator<Rgba32> GetEnumerator()Returns
IEnumerator<Rgba32> The enumerator.
System.Collections.IEnumerable.GetEnumerator()
ImagePalette.csConstants
| Name | Description |
|---|---|
| MaxCount | The largest number of colors of a palette. |
MaxCount
The largest number of colors of a palette.
public const int MaxCount = 256