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
width
intThe width.
height
intThe height.
format
PixelFormatThe format.
rowStride
intThe row pitch.
bufferStride
intThe slice pitch.
dataPointer
IntPtrThe 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
pixelBuffer
PixelBufferThe 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
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 : struct
Parameters
yOffset
intThe 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 : struct
Parameters
pixels
T[]An allocated scanline pixel buffer
yOffset
intThe 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 : struct
Parameters
pixels
T[]An allocated scanline pixel buffer
yOffset
intThe y line offset.
pixelIndex
intOffset into the destination
pixels
buffer.pixelCount
intNumber of pixels to write into the destination
pixels
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
Save(Stream, ImageFileType)
Saves this pixel buffer to a stream.
public void Save(Stream imageStream, ImageFileType fileType)
Parameters
imageStream
StreamThe destination stream.
fileType
ImageFileTypeSpecify 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
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 : struct
Parameters
sourcePixels
T[]Source pixel buffer
yOffset
intThe 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 : struct
Parameters
sourcePixels
T[]Source pixel buffer
yOffset
intThe y line offset.
pixelIndex
intOffset into the source
sourcePixels
buffer.pixelCount
intNumber of pixels to write into the source
sourcePixels
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