Class PixelBuffer
An unmanaged buffer of pixels.
public sealed class PixelBuffer- Inheritance
- 
      objectPixelBuffer
Constructors
PixelBuffer(int, int, PixelFormat, int, int, nint)
Initializes a new instance of the PixelBuffer struct.
public PixelBuffer(int width, int height, PixelFormat format, int rowStride, int bufferStride, nint dataPointer)Parameters
- widthint
- The width. 
- heightint
- The height. 
- formatPixelFormat
- The format. 
- rowStrideint
- The row pitch. 
- bufferStrideint
- The slice pitch. 
- dataPointernint
- The pixels. 
Properties
BufferStride
Gets the total size in bytes of this pixel buffer.
public int BufferStride { get; }Property Value
- int
- The size in bytes of the pixel buffer. 
DataPointer
Gets the pointer to the pixel buffer.
public nint DataPointer { get; }Property Value
- nint
- The pointer to the pixel buffer. 
Format
Gets the format.
public PixelFormat Format { get; }Property Value
- PixelFormat
- The format. 
Height
Gets the height.
public int Height { get; }Property Value
- int
- The height. 
PixelSize
Gets the pixel size in bytes.
public int PixelSize { get; }Property Value
- int
- The pixel size in bytes. 
RowStride
Gets the row stride in number of bytes.
public int RowStride { get; }Property Value
- int
- The row stride in number of bytes. 
Width
Gets the width.
public int Width { get; }Property Value
- int
- The width. 
Methods
ConvertFormatToNonSRgb()
Converts the format to non sRGB.
public void ConvertFormatToNonSRgb()ConvertFormatToSRgb()
Converts the format to sRGB.
public void ConvertFormatToSRgb()CopyTo(PixelBuffer)
Copies this pixel buffer to a destination pixel buffer.
public void CopyTo(PixelBuffer pixelBuffer)Parameters
- pixelBufferPixelBuffer
- The destination pixel buffer. 
Remarks
The destination pixel buffer must have exactly the same dimensions (width, height) and format than this instance. Destination buffer can have different row stride.
GetPixel<T>(int, int)
Gets the pixel value at a specified position.
public T GetPixel<T>(int x, int y) where T : structParameters
Returns
- T
- The pixel value. 
Type Parameters
- T
- Type of the pixel data 
Remarks
Caution, this method doesn't check bounding.
GetPixels<T>(int)
Gets scanline pixels from the buffer.
public T[] GetPixels<T>(int yOffset = 0) where T : structParameters
- yOffsetint
- The y line offset. 
Returns
- T[]
- Scanline pixels from the buffer 
Type Parameters
- T
- Type of the pixel data 
Remarks
This method is working on a row basis. The yOffset is specifying the first row to get
the pixels from.
Exceptions
- ArgumentException
- If the sizeof(T) is an invalid size 
GetPixels<T>(T[], int)
Gets scanline pixels from the buffer.
public void GetPixels<T>(T[] pixels, int yOffset = 0) where T : structParameters
- pixelsT[]
- An allocated scanline pixel buffer 
- yOffsetint
- The y line offset. 
Type Parameters
- T
- Type of the pixel data 
Remarks
This method is working on a row basis. The yOffset is specifying the first row to get
the pixels from.
Exceptions
- ArgumentException
- If the sizeof(T) is an invalid size 
GetPixels<T>(T[], int, int, int)
Gets scanline pixels from the buffer.
public void GetPixels<T>(T[] pixels, int yOffset, int pixelIndex, int pixelCount) where T : structParameters
- pixelsT[]
- An allocated scanline pixel buffer 
- yOffsetint
- The y line offset. 
- pixelIndexint
- Offset into the destination - pixelsbuffer.
- pixelCountint
- Number of pixels to write into the destination - pixelsbuffer.
Type Parameters
- T
- Type of the pixel data 
Remarks
This method is working on a row basis. The yOffset is specifying the first row to get
the pixels from.
Exceptions
- ArgumentException
- If the sizeof(T) is an invalid size 
Save(Stream, ImageFileType)
Saves this pixel buffer to a stream.
public void Save(Stream imageStream, ImageFileType fileType)Parameters
- imageStreamStream
- The destination stream. 
- fileTypeImageFileType
- Specify the output format. 
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga.
SetPixel<T>(int, int, T)
Gets the pixel value at a specified position.
public void SetPixel<T>(int x, int y, T value) where T : structParameters
Type Parameters
- T
- Type of the pixel data 
Remarks
Caution, this method doesn't check bounding.
SetPixels<T>(T[], int)
Sets scanline pixels to the buffer.
public void SetPixels<T>(T[] sourcePixels, int yOffset = 0) where T : structParameters
- sourcePixelsT[]
- Source pixel buffer 
- yOffsetint
- The y line offset. 
Type Parameters
- T
- Type of the pixel data 
Remarks
This method is working on a row basis. The yOffset is specifying the first row to get
the pixels from.
Exceptions
- ArgumentException
- If the sizeof(T) is an invalid size 
SetPixels<T>(T[], int, int, int)
Sets scanline pixels to the buffer.
public void SetPixels<T>(T[] sourcePixels, int yOffset, int pixelIndex, int pixelCount) where T : structParameters
- sourcePixelsT[]
- Source pixel buffer 
- yOffsetint
- The y line offset. 
- pixelIndexint
- Offset into the source - sourcePixelsbuffer.
- pixelCountint
- Number of pixels to write into the source - sourcePixelsbuffer.
Type Parameters
- T
- Type of the pixel data 
Remarks
This method is working on a row basis. The yOffset is specifying the first row to get
the pixels from.
Exceptions
- ArgumentException
- If the sizeof(T) is an invalid size