Class Image
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
- Inheritance
-
objectImage
- Implements
- Extension Methods
Fields
Description
Description of this image.
public ImageDescription Description
Field Value
Properties
DataPointer
Gets a pointer to the image buffer in memory.
public nint DataPointer { get; }
Property Value
- nint
A pointer to the image buffer in memory.
PixelBuffer
Provides access to all pixel buffers.
public PixelBufferArray PixelBuffer { get; }
Property Value
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
Methods
CalculateMipLevels(int, MipMapCount)
Calculates the number of miplevels for a Texture 1D.
public static int CalculateMipLevels(int width, MipMapCount mipLevels)
Parameters
widthintThe width of the texture.
mipLevelsMipMapCountA 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
- int
The number of miplevels.
CalculateMipLevels(int, int, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, MipMapCount mipLevels)
Parameters
widthintThe width of the texture.
heightintThe height of the texture.
mipLevelsMipMapCountA 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
- int
The number of miplevels.
CalculateMipLevels(int, int, int, MipMapCount)
Calculates the number of miplevels for a Texture 2D.
public static int CalculateMipLevels(int width, int height, int depth, MipMapCount mipLevels)
Parameters
widthintThe width of the texture.
heightintThe height of the texture.
depthintThe depth of the texture.
mipLevelsMipMapCountA 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
- int
The number of miplevels.
CalculateMipSize(int, int)
public static int CalculateMipSize(int width, int mipLevel)
Parameters
Returns
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(int)
public static int CountMips(int width)
Parameters
widthint
Returns
CountMips(int, int)
public static int CountMips(int width, int height)
Parameters
Returns
CountMips(int, int, int)
public static int CountMips(int width, int height, int depth)
Parameters
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
GetMipMapDescription(int)
Gets the mipmap description of this instance for the specified mipmap level.
public MipMapDescription GetMipMapDescription(int mipmap)
Parameters
mipmapintThe mipmap.
Returns
- MipMapDescription
A description of a particular mipmap for this texture.
GetPixelBuffer(int, int)
Gets the pixel buffer for the specified array/z slice and mipmap level.
public PixelBuffer GetPixelBuffer(int arrayOrZSliceIndex, int mipmap)
Parameters
arrayOrZSliceIndexintFor 3D image, the parameter is the Z slice, otherwise it is an index into the texture array.
mipmapintThe mipmap.
Returns
Exceptions
- ArgumentException
If arrayOrZSliceIndex or mipmap are out of range.
GetPixelBuffer(int, int, int)
Gets the pixel buffer for the specified array/z slice and mipmap level.
public PixelBuffer GetPixelBuffer(int arrayIndex, int zIndex, int mipmap)
Parameters
arrayIndexintIndex into the texture array. Must be set to 0 for 3D images.
zIndexintZ index for 3D image. Must be set to 0 for all 1D/2D images.
mipmapintThe mipmap.
Returns
Exceptions
- ArgumentException
If arrayIndex, zIndex or mipmap are out of range.
Load(DataPointer, bool, bool)
Loads an image from an unmanaged memory pointer.
[Obsolete("Use span instead")]
public static Image Load(DataPointer dataBuffer, bool makeACopy = false, bool loadAsSRGB = false)
Parameters
dataBufferDataPointerPointer to an unmanaged memory. If
makeACopyis false, this buffer must be allocated with AllocateMemory(int, int).makeACopyboolTrue to copy the content of the buffer to a new allocated buffer, false otherwise.
loadAsSRGBboolIndicate if the image should be loaded as an sRGB texture
Returns
- Image
An new image.
Remarks
If makeACopy is set to false, the returned image is now the holder of the unmanaged pointer and will release it on Dispose.
Load(byte[], bool)
Loads an image from a managed buffer.
public static Image Load(byte[] buffer, bool loadAsSRGB = false)
Parameters
bufferbyte[]Reference to a managed buffer.
loadAsSRGBboolIndicate if the image should be loaded as an sRGB texture
Returns
- Image
An new image.
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga.
Load(Stream, bool)
Loads the specified image from a stream.
public static Image Load(Stream imageStream, bool loadAsSRGB = false)
Parameters
imageStreamStreamThe image stream.
loadAsSRGBboolIndicate if the image should be loaded as an sRGB texture. If false, the image is loaded in its default format.
Returns
- Image
An new image.
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga.
Load(nint, int, bool, bool)
Loads an image from an unmanaged memory pointer.
public static Image Load(nint dataPointer, int dataSize, bool makeACopy = false, bool loadAsSRGB = false)
Parameters
dataPointernintPointer to an unmanaged memory. If
makeACopyis false, this buffer must be allocated with AllocateMemory(int, int).dataSizeintSize of the unmanaged buffer.
makeACopyboolTrue to copy the content of the buffer to a new allocated buffer, false otherwise.
loadAsSRGBboolIndicate if the image should be loaded as an sRGB texture
Returns
- Image
An new image.
Remarks
If makeACopy is set to false, the returned image is now the holder of the unmanaged pointer and will release it on Dispose.
Load(Span<byte>, bool, bool)
Loads an image from an unmanaged memory pointer.
public static Image Load(Span<byte> dataBuffer, bool makeACopy = false, bool loadAsSRGB = false)
Parameters
dataBufferSpan<byte>Pointer to an unmanaged memory. If
makeACopyis false, this buffer must be allocated with AllocateMemory(int, int).makeACopyboolTrue to copy the content of the buffer to a new allocated buffer, false otherwise.
loadAsSRGBboolIndicate if the image should be loaded as an sRGB texture
Returns
- Image
An new image.
Remarks
If makeACopy is set to false, the returned image is now the holder of the unmanaged pointer and will release it on Dispose.
New(ImageDescription)
Creates a new instance of Image from an image description.
public static Image New(ImageDescription description)
Parameters
descriptionImageDescriptionThe image description.
Returns
- Image
A new image.
New(ImageDescription, nint)
Creates a new instance of Image from an image description.
public static Image New(ImageDescription description, nint dataPointer)
Parameters
descriptionImageDescriptionThe image description.
dataPointernintPointer to an existing buffer.
Returns
- Image
A new image.
New(ImageDescription, nint, int, GCHandle?, bool)
Initializes a new instance of the Image class.
public static Image New(ImageDescription description, nint dataPointer, int offset, GCHandle? handle, bool bufferIsDisposable)
Parameters
descriptionImageDescriptionThe image description.
dataPointernintThe pointer to the data buffer.
offsetintThe offset from the beginning of the data buffer.
handleGCHandle?The handle (optionnal).
bufferIsDisposableboolif set to
true[buffer is disposable].
Returns
Exceptions
- InvalidOperationException
If the format is invalid, or width/height/depth/arraysize is invalid with respect to the dimension.
New1D(int, MipMapCount, PixelFormat, int)
Creates a new instance of a 1D Image.
public static Image New1D(int width, MipMapCount mipMapCount, PixelFormat format, int arraySize = 1)
Parameters
widthintThe width.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
arraySizeintSize of the array.
Returns
- Image
A new image.
New1D(int, MipMapCount, PixelFormat, int, nint)
Creates a new instance of a 1D Image.
public static Image New1D(int width, MipMapCount mipMapCount, PixelFormat format, int arraySize, nint dataPointer)
Parameters
widthintThe width.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
arraySizeintSize of the array.
dataPointernintPointer to an existing buffer.
Returns
- Image
A new image.
New2D(int, int, MipMapCount, PixelFormat, int, int)
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
widthintThe width.
heightintThe height.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
arraySizeintSize of the array.
rowStrideint
Returns
- Image
A new image.
New2D(int, int, MipMapCount, PixelFormat, int, nint, int)
Creates a new instance of a 2D Image.
public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize, nint dataPointer, int rowStride = 0)
Parameters
widthintThe width.
heightintThe height.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
arraySizeintSize of the array.
dataPointernintPointer to an existing buffer.
rowStrideintSpecify a specific rowStride, only valid when mipMapCount == 1 and pixel format is not compressed.
Returns
- Image
A new image.
New3D(int, int, int, 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
widthintThe width.
heightintThe height.
depthintThe depth.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
Returns
- Image
A new image.
New3D(int, int, int, MipMapCount, PixelFormat, nint)
Creates a new instance of a 3D Image.
public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format, nint dataPointer)
Parameters
widthintThe width.
heightintThe height.
depthintThe depth.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
dataPointernintPointer to an existing buffer.
Returns
- Image
A new image.
NewCube(int, MipMapCount, PixelFormat)
Creates a new instance of a Cube Image.
public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format)
Parameters
widthintThe width.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
Returns
- Image
A new image.
NewCube(int, MipMapCount, PixelFormat, nint)
Creates a new instance of a Cube Image.
public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format, nint dataPointer)
Parameters
widthintThe width.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
dataPointernintPointer to an existing buffer.
Returns
- Image
A new image.
Register(ImageFileType, ImageLoadDelegate, ImageSaveDelegate)
Registers a loader/saver for a specified image file type.
public static void Register(ImageFileType type, Image.ImageLoadDelegate loader, Image.ImageSaveDelegate saver)
Parameters
typeImageFileTypeThe file type (use integer and explicit casting to ImageFileType to register other fileformat.
loaderImage.ImageLoadDelegateThe loader delegate (can be null).
saverImage.ImageSaveDelegateThe saver delegate (can be null).
Exceptions
Save(Stream, ImageFileType)
Saves this instance 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.
ToDataBox()
Gets the databox from this image.
public DataBox[] ToDataBox()
Returns
- DataBox[]
The databox of this image.