Image Class
Namespace: Stride.GraphicsAssembly: Stride.dll
Provides method to instantiate an image 1D/2D/3D supporting TextureArray and mipmaps on the CPU or to load/save an image from the disk.
[ContentSerializer(typeof(ImageSerializer))]
public sealed class Image : IDisposable
Name | Description | |
---|---|---|
Fields | ||
Description | Description of this image. |
|
Properties | ||
DataPointer | Gets a pointer to the image buffer in memory. |
|
PixelBuffer | Provides access to all pixel buffers. |
|
TotalSizeInBytes | Gets the total number of bytes occupied by this image in memory. |
|
Methods | ||
CalculateMipLevels(Int32, MipMapCount) | Calculates the number of miplevels for a Texture 1D. |
|
CalculateMipLevels(Int32, Int32, MipMapCount) | Calculates the number of miplevels for a Texture 2D. |
|
CalculateMipLevels(Int32, Int32, Int32, MipMapCount) | Calculates the number of miplevels for a Texture 2D. |
|
CalculateMipSize(Int32, Int32) | ||
Clear() | Reset the buffer (by default it is not cleared) |
|
ConvertFormatToNonSRgb() | Converts the format of the description and the pixel buffers to non sRGB. |
|
ConvertFormatToSRgb() | Converts the format of the description and the pixel buffers to sRGB. |
|
CountMips(Int32) | ||
CountMips(Int32, Int32) | ||
CountMips(Int32, Int32, Int32) | ||
Dispose() | ||
GetMipMapDescription(Int32) | Gets the mipmap description of this instance for the specified mipmap level. |
|
GetPixelBuffer(Int32, Int32) | Gets the pixel buffer for the specified array/z slice and mipmap level. |
|
GetPixelBuffer(Int32, Int32, Int32) | Gets the pixel buffer for the specified array/z slice and mipmap level. |
|
Load(DataPointer, Boolean, Boolean) | Loads an image from an unmanaged memory pointer. |
|
Load(Byte[], Boolean) | Loads an image from a managed buffer. |
|
Load(IntPtr, Int32, Boolean, Boolean) | Loads an image from an unmanaged memory pointer. |
|
Load(Stream, Boolean) | Loads the specified image from a stream. |
|
New(ImageDescription) | Creates a new instance of Image from an image description. |
|
New(ImageDescription, IntPtr) | Creates a new instance of Image from an image description. |
|
New(ImageDescription, IntPtr, Int32, Nullable<GCHandle>, Boolean) | Initializes a new instance of the Image class. |
|
New1D(Int32, MipMapCount, PixelFormat, Int32) | Creates a new instance of a 1D Image. |
|
New1D(Int32, MipMapCount, PixelFormat, Int32, IntPtr) | Creates a new instance of a 1D Image. |
|
New2D(Int32, Int32, MipMapCount, PixelFormat, Int32, Int32) | Creates a new instance of a 2D Image. |
|
New2D(Int32, Int32, MipMapCount, PixelFormat, Int32, IntPtr, Int32) | Creates a new instance of a 2D Image. |
|
New3D(Int32, Int32, Int32, MipMapCount, PixelFormat) | Creates a new instance of a 3D Image. |
|
New3D(Int32, Int32, Int32, MipMapCount, PixelFormat, IntPtr) | Creates a new instance of a 3D Image. |
|
NewCube(Int32, MipMapCount, PixelFormat) | Creates a new instance of a Cube Image. |
|
NewCube(Int32, MipMapCount, PixelFormat, IntPtr) | Creates a new instance of a Cube Image. |
|
Register(ImageFileType, Image.ImageLoadDelegate, Image.ImageSaveDelegate) | Registers a loader/saver for a specified image file type. |
|
Save(Stream, ImageFileType) | Saves this instance to a stream. |
|
ToDataBox() | Gets the databox from this image. |
Fields
Description
Description of this image.
public ImageDescription Description
Field Value
Type | Description |
---|---|
ImageDescription |
Properties
DataPointer
Gets a pointer to the image buffer in memory.
public IntPtr DataPointer { get; }
Property Value
Type | Description |
---|---|
System.IntPtr | A pointer to the image buffer in memory. |
PixelBuffer
Provides access to all pixel buffers.
public PixelBufferArray PixelBuffer { get; }
Property Value
Type | Description |
---|---|
PixelBufferArray |
Remarks
For Texture3D, each z slice of the Texture3D has a pixelBufferArray * by the number of mipmaps. For other textures, there is Description.MipLevels * Description.ArraySize pixel buffers.
TotalSizeInBytes
Gets the total number of bytes occupied by this image in memory.
public int TotalSizeInBytes { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
CalculateMipLevels(Int32, MipMapCount)
Calculates the number of miplevels for a Texture 1D.
public static int CalculateMipLevels(int width, MipMapCount mipLevels)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width of the texture. |
MipMapCount | mipLevels | A MipMapCount, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels. |
Returns
Type | Description |
---|---|
System.Int32 | The number of miplevels. |
CalculateMipLevels(Int32, Int32, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, MipMapCount mipLevels)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width of the texture. |
System.Int32 | height | The height of the texture. |
MipMapCount | mipLevels | A MipMapCount, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels. |
Returns
Type | Description |
---|---|
System.Int32 | The number of miplevels. |
CalculateMipLevels(Int32, Int32, Int32, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, int depth, MipMapCount mipLevels)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width of the texture. |
System.Int32 | height | The height of the texture. |
System.Int32 | depth | The depth of the texture. |
MipMapCount | mipLevels | A MipMapCount, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels. |
Returns
Type | Description |
---|---|
System.Int32 | The number of miplevels. |
CalculateMipSize(Int32, Int32)
public static int CalculateMipSize(int width, int mipLevel)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | |
System.Int32 | mipLevel |
Returns
Type | Description |
---|---|
System.Int32 |
Clear()
Reset the buffer (by default it is not cleared)
public void Clear()
ConvertFormatToNonSRgb()
Converts the format of the description and the pixel buffers to non sRGB.
public void ConvertFormatToNonSRgb()
ConvertFormatToSRgb()
Converts the format of the description and the pixel buffers to sRGB.
public void ConvertFormatToSRgb()
CountMips(Int32)
public static int CountMips(int width)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width |
Returns
Type | Description |
---|---|
System.Int32 |
CountMips(Int32, Int32)
public static int CountMips(int width, int height)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | |
System.Int32 | height |
Returns
Type | Description |
---|---|
System.Int32 |
CountMips(Int32, Int32, Int32)
public static int CountMips(int width, int height, int depth)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | |
System.Int32 | height | |
System.Int32 | depth |
Returns
Type | Description |
---|---|
System.Int32 |
Dispose()
public void Dispose()
GetMipMapDescription(Int32)
Gets the mipmap description of this instance for the specified mipmap level.
public MipMapDescription GetMipMapDescription(int mipmap)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | mipmap | The mipmap. |
Returns
Type | Description |
---|---|
MipMapDescription | A description of a particular mipmap for this texture. |
GetPixelBuffer(Int32, Int32)
Gets the pixel buffer for the specified array/z slice and mipmap level.
public PixelBuffer GetPixelBuffer(int arrayOrZSliceIndex, int mipmap)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | arrayOrZSliceIndex | For 3D image, the parameter is the Z slice, otherwise it is an index into the texture array. |
System.Int32 | mipmap | The mipmap. |
Returns
Type | Description |
---|---|
PixelBuffer | A Stride.Graphics.Image.pixelBufferArray. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If arrayOrZSliceIndex or mipmap are out of range. |
GetPixelBuffer(Int32, Int32, Int32)
Gets the pixel buffer for the specified array/z slice and mipmap level.
public PixelBuffer GetPixelBuffer(int arrayIndex, int zIndex, int mipmap)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | arrayIndex | Index into the texture array. Must be set to 0 for 3D images. |
System.Int32 | zIndex | Z index for 3D image. Must be set to 0 for all 1D/2D images. |
System.Int32 | mipmap | The mipmap. |
Returns
Type | Description |
---|---|
PixelBuffer | A Stride.Graphics.Image.pixelBufferArray. |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If arrayIndex, zIndex or mipmap are out of range. |
Load(DataPointer, Boolean, Boolean)
Loads an image from an unmanaged memory pointer.
public static Image Load(DataPointer dataBuffer, bool makeACopy = false, bool loadAsSRGB = false)
Parameters
Type | Name | Description |
---|---|---|
DataPointer | dataBuffer | Pointer to an unmanaged memory. If |
System.Boolean | makeACopy | True to copy the content of the buffer to a new allocated buffer, false otherwise. |
System.Boolean | loadAsSRGB | Indicate if the image should be loaded as an sRGB texture |
Returns
Type | Description |
---|---|
Image | An new image. |
Remarks
If
Load(Byte[], Boolean)
Loads an image from a managed buffer.
public static Image Load(byte[] buffer, bool loadAsSRGB = false)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | buffer | Reference to a managed buffer. |
System.Boolean | loadAsSRGB | Indicate if the image should be loaded as an sRGB texture |
Returns
Type | Description |
---|---|
Image | An new image. |
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga
.
Load(IntPtr, Int32, Boolean, Boolean)
Loads an image from an unmanaged memory pointer.
public static Image Load(IntPtr dataPointer, int dataSize, bool makeACopy = false, bool loadAsSRGB = false)
Parameters
Type | Name | Description |
---|---|---|
System.IntPtr | dataPointer | Pointer to an unmanaged memory. If |
System.Int32 | dataSize | Size of the unmanaged buffer. |
System.Boolean | makeACopy | True to copy the content of the buffer to a new allocated buffer, false otherwise. |
System.Boolean | loadAsSRGB | Indicate if the image should be loaded as an sRGB texture |
Returns
Type | Description |
---|---|
Image | An new image. |
Remarks
If
Load(Stream, Boolean)
Loads the specified image from a stream.
public static Image Load(Stream imageStream, bool loadAsSRGB = false)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | imageStream | The image stream. |
System.Boolean | loadAsSRGB | Indicate if the image should be loaded as an sRGB texture. If false, the image is loaded in its default format. |
Returns
Type | Description |
---|---|
Image | An new image. |
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga
.
New(ImageDescription)
Creates a new instance of Image from an image description.
public static Image New(ImageDescription description)
Parameters
Type | Name | Description |
---|---|---|
ImageDescription | description | The image description. |
Returns
Type | Description |
---|---|
Image | A new image. |
New(ImageDescription, IntPtr)
Creates a new instance of Image from an image description.
public static Image New(ImageDescription description, IntPtr dataPointer)
Parameters
Type | Name | Description |
---|---|---|
ImageDescription | description | The image description. |
System.IntPtr | dataPointer | Pointer to an existing buffer. |
Returns
Type | Description |
---|---|
Image | A new image. |
New(ImageDescription, IntPtr, Int32, Nullable<GCHandle>, Boolean)
Initializes a new instance of the Image class.
public static Image New(ImageDescription description, IntPtr dataPointer, int offset, GCHandle? handle, bool bufferIsDisposable)
Parameters
Type | Name | Description |
---|---|---|
ImageDescription | description | The image description. |
System.IntPtr | dataPointer | The pointer to the data buffer. |
System.Int32 | offset | The offset from the beginning of the data buffer. |
System.Nullable<System.Runtime.InteropServices.GCHandle> | handle | The handle (optionnal). |
System.Boolean | bufferIsDisposable | if set to |
Returns
Type | Description |
---|---|
Image |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the format is invalid, or width/height/depth/arraysize is invalid with respect to the dimension. |
New1D(Int32, MipMapCount, PixelFormat, Int32)
Creates a new instance of a 1D Image.
public static Image New1D(int width, MipMapCount mipMapCount, PixelFormat format, int arraySize = 1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
System.Int32 | arraySize | Size of the array. |
Returns
Type | Description |
---|---|
Image | A new image. |
New1D(Int32, MipMapCount, PixelFormat, Int32, IntPtr)
Creates a new instance of a 1D Image.
public static Image New1D(int width, MipMapCount mipMapCount, PixelFormat format, int arraySize, IntPtr dataPointer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
System.Int32 | arraySize | Size of the array. |
System.IntPtr | dataPointer | Pointer to an existing buffer. |
Returns
Type | Description |
---|---|
Image | A new image. |
New2D(Int32, Int32, MipMapCount, PixelFormat, Int32, Int32)
Creates a new instance of a 2D Image.
public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize = 1, int rowStride = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
System.Int32 | height | The height. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
System.Int32 | arraySize | Size of the array. |
System.Int32 | rowStride |
Returns
Type | Description |
---|---|
Image | A new image. |
New2D(Int32, Int32, MipMapCount, PixelFormat, Int32, IntPtr, Int32)
Creates a new instance of a 2D Image.
public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize, IntPtr dataPointer, int rowStride = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
System.Int32 | height | The height. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
System.Int32 | arraySize | Size of the array. |
System.IntPtr | dataPointer | Pointer to an existing buffer. |
System.Int32 | rowStride | Specify a specific rowStride, only valid when mipMapCount == 1 and pixel format is not compressed. |
Returns
Type | Description |
---|---|
Image | A new image. |
New3D(Int32, Int32, Int32, MipMapCount, PixelFormat)
Creates a new instance of a 3D Image.
public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
System.Int32 | height | The height. |
System.Int32 | depth | The depth. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
Returns
Type | Description |
---|---|
Image | A new image. |
New3D(Int32, Int32, Int32, MipMapCount, PixelFormat, IntPtr)
Creates a new instance of a 3D Image.
public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format, IntPtr dataPointer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
System.Int32 | height | The height. |
System.Int32 | depth | The depth. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
System.IntPtr | dataPointer | Pointer to an existing buffer. |
Returns
Type | Description |
---|---|
Image | A new image. |
NewCube(Int32, MipMapCount, PixelFormat)
Creates a new instance of a Cube Image.
public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
Returns
Type | Description |
---|---|
Image | A new image. |
NewCube(Int32, MipMapCount, PixelFormat, IntPtr)
Creates a new instance of a Cube Image.
public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format, IntPtr dataPointer)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | width | The width. |
MipMapCount | mipMapCount | The mip map count. |
PixelFormat | format | The format. |
System.IntPtr | dataPointer | Pointer to an existing buffer. |
Returns
Type | Description |
---|---|
Image | A new image. |
Register(ImageFileType, Image.ImageLoadDelegate, Image.ImageSaveDelegate)
Registers a loader/saver for a specified image file type.
public static void Register(ImageFileType type, Image.ImageLoadDelegate loader, Image.ImageSaveDelegate saver)
Parameters
Type | Name | Description |
---|---|---|
ImageFileType | type | The file type (use integer and explicit casting to ImageFileType to register other fileformat. |
Image.ImageLoadDelegate | loader | The loader delegate (can be null). |
Image.ImageSaveDelegate | saver | The saver delegate (can be null). |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
Save(Stream, ImageFileType)
Saves this instance 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
.
ToDataBox()
Gets the databox from this image.
public DataBox[] ToDataBox()
Returns
Type | Description |
---|---|
DataBox[] | The databox of this image. |