PixelFormats Class

Provides information about the built-in pixel formats and maps pixel structs to PixelFormat values.

public static class PixelFormats

Remarks

Typed APIs constrain their pixel type parameter with where TPixel : unmanaged only. Unmanaged types that are not one of the built-in pixel structs are rejected with a NotSupportedException before any I/O or allocation happens. There is no public pixel-implementation contract in this version.

Properties

NameDescription
AllGets the pixel formats supported by this version, in declaration order.

Gets the pixel formats supported by this version, in declaration order.

public static IReadOnlyList<PixelFormat> All { get; }

Methods

NameDescription
GetBitsPerComponent(PixelFormat)Gets the number of bits used to store each component.
GetBytesPerPixel(PixelFormat)Gets the number of bytes used to store one pixel.
GetComponentCount(PixelFormat)Gets the number of components (channels) of a pixel, including alpha.
GetPixelFormat<TPixel>()Gets the PixelFormat corresponding to TPixel.
GetPixelType(PixelFormat)Gets the CLR pixel struct type corresponding to a pixel format.
HasAlpha(PixelFormat)Determines whether the pixel format stores an alpha component.
HasColor(PixelFormat)Determines whether the pixel format stores a color (gray or red, green and blue components).
IsFloatingPoint(PixelFormat)Determines whether the pixel format stores floating-point components.
IsGrayscale(PixelFormat)Determines whether the pixel format is grayscale.
IsSupported<TPixel>()Determines whether TPixel is one of the built-in pixel structs.

GetBitsPerComponent(PixelFormat)

PixelFormats.cs

Gets the number of bits used to store each component.

public static int GetBitsPerComponent(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

int 8 or 16 for the integer formats; 32 for PixelFormat.RgbaFloat and 16 for PixelFormat.RgbaHalf (see PixelFormats.IsFloatingPoint). The packed formats, whose components do not all have the same size, give the bits of their largest component: 6 for PixelFormat.Bgr565 (5-bit red and blue, 6-bit green) and 10 for PixelFormat.Rgba1010102 (10-bit colors, 2-bit alpha).

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

GetBytesPerPixel(PixelFormat)

PixelFormats.cs

Gets the number of bytes used to store one pixel.

public static int GetBytesPerPixel(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

int The number of bytes per pixel.

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

GetComponentCount(PixelFormat)

PixelFormats.cs

Gets the number of components (channels) of a pixel, including alpha.

public static int GetComponentCount(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

int The number of components.

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

GetPixelFormat<TPixel>()

PixelFormats.cs

Gets the PixelFormat corresponding to TPixel.

public static PixelFormat GetPixelFormat<TPixel>() where TPixel : unmanaged

Type parameters

TPixel
The pixel type.

Returns

PixelFormat The pixel format.

Exceptions

NotSupportedException
TPixel is not a built-in pixel struct.

GetPixelType(PixelFormat)

PixelFormats.cs

Gets the CLR pixel struct type corresponding to a pixel format.

public static Type GetPixelType(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

Type The pixel struct type.

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

HasAlpha(PixelFormat)

PixelFormats.cs

Determines whether the pixel format stores an alpha component.

public static bool HasAlpha(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

bool true if the format has a (straight) alpha component; otherwise false.

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

HasColor(PixelFormat)

PixelFormats.cs

Determines whether the pixel format stores a color (gray or red, green and blue components).

public static bool HasColor(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

bool false for PixelFormat.A8, an alpha mask whose pixels read as black; otherwise true.

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

IsFloatingPoint(PixelFormat)

PixelFormats.cs

Determines whether the pixel format stores floating-point components.

public static bool IsFloatingPoint(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

bool true for PixelFormat.RgbaFloat and PixelFormat.RgbaHalf, whose components are not limited to [0, 1]; false for the integer formats, whose components go from 0 to the largest value of their bits.

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

IsGrayscale(PixelFormat)

PixelFormats.cs

Determines whether the pixel format is grayscale.

public static bool IsGrayscale(PixelFormat format)

Parameters

format PixelFormat
The pixel format.

Returns

bool true if the format stores a single gray component, with or without alpha (PixelFormat.Gray8, PixelFormat.Gray16, PixelFormat.La16 and PixelFormat.La32); otherwise false, also for PixelFormat.A8, which stores no color (see PixelFormats.HasColor).

Exceptions

ArgumentOutOfRangeException
format is not a supported pixel format.

IsSupported<TPixel>()

PixelFormats.cs

Determines whether TPixel is one of the built-in pixel structs.

public static bool IsSupported<TPixel>() where TPixel : unmanaged

Type parameters

TPixel
The pixel type.

Returns

bool true if the type is supported; otherwise false.