PixelBuffer Class
Namespace: Stride.GraphicsAssembly: Stride.dll
An unmanaged buffer of pixels.
public sealed class PixelBuffer
| Name | Description | |
|---|---|---|
| Constructors | ||
| PixelBuffer(Int32, Int32, PixelFormat, Int32, Int32, IntPtr) | Initializes a new instance of the PixelBuffer struct. |
|
| Properties | ||
| BufferStride | Gets the total size in bytes of this pixel buffer. |
|
| DataPointer | Gets the pointer to the pixel buffer. |
|
| Format | Gets the format. |
|
| Height | Gets the height. |
|
| PixelSize | Gets the pixel size in bytes. |
|
| RowStride | Gets the row stride in number of bytes. |
|
| Width | Gets the width. |
|
| Methods | ||
| ConvertFormatToNonSRgb() | Converts the format to non sRGB. |
|
| ConvertFormatToSRgb() | Converts the format to sRGB. |
|
| CopyTo(PixelBuffer) | Copies this pixel buffer to a destination pixel buffer. |
|
| GetPixel<T>(Int32, Int32) | Gets the pixel value at a specified position. |
|
| GetPixels<T>(T[], Int32) | Gets scanline pixels from the buffer. |
|
| GetPixels<T>(T[], Int32, Int32, Int32) | Gets scanline pixels from the buffer. |
|
| GetPixels<T>(Int32) | Gets scanline pixels from the buffer. |
|
| Save(Stream, ImageFileType) | Saves this pixel buffer to a stream. |
|
| SetPixel<T>(Int32, Int32, T) | Gets the pixel value at a specified position. |
|
| SetPixels<T>(T[], Int32) | Sets scanline pixels to the buffer. |
|
| SetPixels<T>(T[], Int32, Int32, Int32) | Sets scanline pixels to the buffer. |
|
Constructors
PixelBuffer(Int32, Int32, PixelFormat, Int32, Int32, IntPtr)
Initializes a new instance of the PixelBuffer struct.
public PixelBuffer(int width, int height, PixelFormat format, int rowStride, int bufferStride, IntPtr dataPointer)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | width | The width. |
| System.Int32 | height | The height. |
| PixelFormat | format | The format. |
| System.Int32 | rowStride | The row pitch. |
| System.Int32 | bufferStride | The slice pitch. |
| System.IntPtr | dataPointer | The pixels. |
Properties
BufferStride
Gets the total size in bytes of this pixel buffer.
public int BufferStride { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The size in bytes of the pixel buffer. |
DataPointer
Gets the pointer to the pixel buffer.
public IntPtr DataPointer { get; }
Property Value
| Type | Description |
|---|---|
| System.IntPtr | The pointer to the pixel buffer. |
Format
Gets the format.
public PixelFormat Format { get; }
Property Value
| Type | Description |
|---|---|
| PixelFormat | The format. |
Height
Gets the height.
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The height. |
PixelSize
Gets the pixel size in bytes.
public int PixelSize { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The pixel size in bytes. |
RowStride
Gets the row stride in number of bytes.
public int RowStride { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | The row stride in number of bytes. |
Width
Gets the width.
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | 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
| Type | Name | Description |
|---|---|---|
| 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>(Int32, Int32)
Gets the pixel value at a specified position.
public T GetPixel<T>(int x, int y)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | The x-coordinate. |
| System.Int32 | y | The y-coordinate. |
Returns
| Type | Description |
|---|---|
| T | The pixel value. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the pixel data |
Remarks
Caution, this method doesn't check bounding.
GetPixels<T>(T[], Int32)
Gets scanline pixels from the buffer.
public void GetPixels<T>(T[] pixels, int yOffset = 0)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | pixels | An allocated scanline pixel buffer |
| System.Int32 | yOffset | The y line offset. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the pixel data |
Remarks
This method is working on a row basis. The
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | If the sizeof(T) is an invalid size |
GetPixels<T>(T[], Int32, Int32, Int32)
Gets scanline pixels from the buffer.
public void GetPixels<T>(T[] pixels, int yOffset, int pixelIndex, int pixelCount)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | pixels | An allocated scanline pixel buffer |
| System.Int32 | yOffset | The y line offset. |
| System.Int32 | pixelIndex | Offset into the destination |
| System.Int32 | pixelCount | Number of pixels to write into the destination |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the pixel data |
Remarks
This method is working on a row basis. The
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | If the sizeof(T) is an invalid size |
GetPixels<T>(Int32)
Gets scanline pixels from the buffer.
public T[] GetPixels<T>(int yOffset = 0)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | yOffset | The y line offset. |
Returns
| Type | Description |
|---|---|
| T[] | Scanline pixels from the buffer |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the pixel data |
Remarks
This method is working on a row basis. The
Exceptions
| Type | Condition |
|---|---|
| System.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
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | imageStream | The destination stream. |
| ImageFileType | fileType | Specify the output format. |
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga.
SetPixel<T>(Int32, Int32, T)
Gets the pixel value at a specified position.
public void SetPixel<T>(int x, int y, T value)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | x | The x-coordinate. |
| System.Int32 | y | The y-coordinate. |
| T | value | The pixel value. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the pixel data |
Remarks
Caution, this method doesn't check bounding.
SetPixels<T>(T[], Int32)
Sets scanline pixels to the buffer.
public void SetPixels<T>(T[] sourcePixels, int yOffset = 0)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | sourcePixels | Source pixel buffer |
| System.Int32 | yOffset | The y line offset. |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the pixel data |
Remarks
This method is working on a row basis. The
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | If the sizeof(T) is an invalid size |
SetPixels<T>(T[], Int32, Int32, Int32)
Sets scanline pixels to the buffer.
public void SetPixels<T>(T[] sourcePixels, int yOffset, int pixelIndex, int pixelCount)
where T : struct
Parameters
| Type | Name | Description |
|---|---|---|
| T[] | sourcePixels | Source pixel buffer |
| System.Int32 | yOffset | The y line offset. |
| System.Int32 | pixelIndex | Offset into the source |
| System.Int32 | pixelCount | Number of pixels to write into the source |
Type Parameters
| Name | Description |
|---|---|
| T | Type of the pixel data |
Remarks
This method is working on a row basis. The
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | If the sizeof(T) is an invalid size |