PixelFormats Class
Provides information about the built-in pixel formats and maps pixel structs to PixelFormat values.
public static class PixelFormatsRemarks
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
| Name | Description |
|---|---|
| All | Gets 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; }Property value
Methods
| Name | Description |
|---|---|
| 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.csGets the number of bits used to store each component.
public static int GetBitsPerComponent(PixelFormat format)Parameters
formatPixelFormat- 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
ArgumentOutOfRangeExceptionformatis not a supported pixel format.
GetBytesPerPixel(PixelFormat)
PixelFormats.csGets the number of bytes used to store one pixel.
public static int GetBytesPerPixel(PixelFormat format)Parameters
formatPixelFormat- The pixel format.
Returns
int The number of bytes per pixel.
Exceptions
ArgumentOutOfRangeExceptionformatis not a supported pixel format.
GetComponentCount(PixelFormat)
PixelFormats.csGets the number of components (channels) of a pixel, including alpha.
public static int GetComponentCount(PixelFormat format)Parameters
formatPixelFormat- The pixel format.
Returns
int The number of components.
Exceptions
ArgumentOutOfRangeExceptionformatis not a supported pixel format.
GetPixelFormat<TPixel>()
PixelFormats.csGets the PixelFormat corresponding to TPixel.
public static PixelFormat GetPixelFormat<TPixel>() where TPixel : unmanagedType parameters
TPixel- The pixel type.
Returns
PixelFormat The pixel format.
Exceptions
NotSupportedExceptionTPixelis not a built-in pixel struct.
GetPixelType(PixelFormat)
PixelFormats.csGets the CLR pixel struct type corresponding to a pixel format.
public static Type GetPixelType(PixelFormat format)Parameters
formatPixelFormat- The pixel format.
Returns
Type The pixel struct type.
Exceptions
ArgumentOutOfRangeExceptionformatis not a supported pixel format.
HasAlpha(PixelFormat)
PixelFormats.csDetermines whether the pixel format stores an alpha component.
public static bool HasAlpha(PixelFormat format)Parameters
formatPixelFormat- The pixel format.
Returns
bool true if the format has a (straight) alpha component; otherwise false.
Exceptions
ArgumentOutOfRangeExceptionformatis not a supported pixel format.
HasColor(PixelFormat)
PixelFormats.csDetermines whether the pixel format stores a color (gray or red, green and blue components).
public static bool HasColor(PixelFormat format)Parameters
formatPixelFormat- The pixel format.
Returns
bool false for PixelFormat.A8, an alpha mask whose pixels read as black; otherwise true.
Exceptions
ArgumentOutOfRangeExceptionformatis not a supported pixel format.
IsFloatingPoint(PixelFormat)
PixelFormats.csDetermines whether the pixel format stores floating-point components.
public static bool IsFloatingPoint(PixelFormat format)Parameters
formatPixelFormat- 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
ArgumentOutOfRangeExceptionformatis not a supported pixel format.
IsGrayscale(PixelFormat)
PixelFormats.csDetermines whether the pixel format is grayscale.
public static bool IsGrayscale(PixelFormat format)Parameters
formatPixelFormat- 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
ArgumentOutOfRangeExceptionformatis not a supported pixel format.