Table of Contents

Class PixelBuffer

Namespace
SharpDX.Toolkit.Graphics
Assembly
HelixToolkit.SharpDX.dll

An unmanaged buffer of pixels.

public sealed class PixelBuffer
Inheritance
PixelBuffer
Inherited Members

Constructors

PixelBuffer(int, int, Format, int, int, nint)

Initializes a new instance of the PixelBuffer struct.

public PixelBuffer(int width, int height, Format format, int rowStride, int bufferStride, nint dataPointer)

Parameters

width int

The width.

height int

The height.

format Format

The format.

rowStride int

The row pitch.

bufferStride int

The slice pitch.

dataPointer nint

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 (this value can be changed)

public Format Format { get; set; }

Property Value

Format

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

CopyTo(PixelBuffer)

Copies this pixel buffer to a destination pixel buffer.

public void CopyTo(PixelBuffer pixelBuffer)

Parameters

pixelBuffer PixelBuffer

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 : unmanaged

Parameters

x int

The x-coordinate.

y int

The y-coordinate.

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 : unmanaged

Parameters

yOffset int

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 : unmanaged

Parameters

pixels T[]

An allocated scanline pixel buffer

yOffset int

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 : unmanaged

Parameters

pixels T[]

An allocated scanline pixel buffer

yOffset int

The y line offset.

pixelIndex int

Offset into the destination pixels buffer.

pixelCount int

Number 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

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 : unmanaged

Parameters

x int

The x-coordinate.

y int

The y-coordinate.

value T

The pixel value.

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 : unmanaged

Parameters

sourcePixels T[]

Source pixel buffer

yOffset int

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 : unmanaged

Parameters

sourcePixels T[]

Source pixel buffer

yOffset int

The y line offset.

pixelIndex int

Offset into the source sourcePixels buffer.

pixelCount int

Number 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