Class PixelBuffer
An unmanaged buffer of pixels.
public sealed class PixelBuffer
- Inheritance
-
PixelBuffer
Constructors
PixelBuffer(int, int, PixelFormat, int, int, IntPtr)
Initializes a new instance of the PixelBuffer struct.
public PixelBuffer(int width, int height, PixelFormat format, int rowStride, int bufferStride, IntPtr dataPointer)
Parameters
widthintThe width.
heightintThe height.
formatPixelFormatThe format.
rowStrideintThe row pitch.
bufferStrideintThe slice pitch.
dataPointerIntPtrThe 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 IntPtr DataPointer { get; }
Property Value
- IntPtr
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
pixelBufferPixelBufferThe 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 : struct
Parameters
Returns
- T
The pixel value.
Type Parameters
TType 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 : struct
Parameters
yOffsetintThe y line offset.
Returns
- T[]
Scanline pixels from the buffer
Type Parameters
TType 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 : struct
Parameters
pixelsT[]An allocated scanline pixel buffer
yOffsetintThe y line offset.
Type Parameters
TType 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 : struct
Parameters
pixelsT[]An allocated scanline pixel buffer
yOffsetintThe y line offset.
pixelIndexintOffset into the destination
pixelsbuffer.pixelCountintNumber of pixels to write into the destination
pixelsbuffer.
Type Parameters
TType 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
imageStreamStreamThe destination stream.
fileTypeImageFileTypeSpecify 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 : struct
Parameters
Type Parameters
TType 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 : struct
Parameters
sourcePixelsT[]Source pixel buffer
yOffsetintThe y line offset.
Type Parameters
TType 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 : struct
Parameters
sourcePixelsT[]Source pixel buffer
yOffsetintThe y line offset.
pixelIndexintOffset into the source
sourcePixelsbuffer.pixelCountintNumber of pixels to write into the source
sourcePixelsbuffer.
Type Parameters
TType 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