Table of Contents

Class Palette

Namespace
Sdl3Sharp.Video.Coloring
Assembly
Sdl3Sharp.dll

Represents a palette of colors

public sealed class Palette : IDisposable, ISpanFormattable, IFormattable, IEnumerable<Color<byte>>, IEnumerable
Inheritance
Palette
Implements
Inherited Members

Constructors

Palette(int)

Creates a new Palette with a specified number of colors

public Palette(int length)

Parameters

length int

The number of color entries in the palette

Remarks

All palette entries are initialized to be fully white and fully opaque. Use TrySetColors(ReadOnlySpan<Color<byte>>, int) to change the colors in the palette.

Properties

Colors

Gets the colors in the palette

public ReadOnlySpan<Color<byte>> Colors { get; }

Property Value

ReadOnlySpan<Color<byte>>

The colors in the palette

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Remarks

Don't use the value of the Colors property or any copies or slices of that value (ReadOnlySpan<T>) after disposing the Palette!

~Palette()

protected ~Palette()

GetEnumerator()

Gets an Palette.Enumerator that enumerates the colors in the palette

public Palette.Enumerator GetEnumerator()

Returns

Palette.Enumerator

Exceptions

ArgumentNullException

palette is null

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToString(IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(IFormatProvider? formatProvider)

Parameters

formatProvider IFormatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

ToString(string?)

Formats the value of the current instance using the specified format.

public string ToString(string? format)

Parameters

format string

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

Returns

string

The value of the current instance in the specified format.

ToString(string?, IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

formatProvider IFormatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Tries to format the value of the current instance into the provided span of characters.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)

Parameters

destination Span<char>

The span in which to write this instance's value formatted as a span of characters.

charsWritten int

When this method returns, contains the number of characters that were written in destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.

provider IFormatProvider

An optional object that supplies culture-specific formatting information for destination.

Returns

bool

true if the formatting was successful; otherwise, false.

TrySetColors(ReadOnlySpan<Color<byte>>, int)

Tries to set a range of colors in the palette

public bool TrySetColors(ReadOnlySpan<Color<byte>> colors, int offset = 0)

Parameters

colors ReadOnlySpan<Color<byte>>

The colors to copy into the palette

offset int

The index of the first palette entry to modify (offset into the palette)

Returns

bool

true, if the provided range of colors was successfully copied into the palette; otherwise, false (check TryGet(out string?) for more information)