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
-
Image
- 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
width
intThe width of the texture.
mipLevels
MipMapCountA 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
width
intThe width of the texture.
height
intThe height of the texture.
mipLevels
MipMapCountA 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
width
intThe width of the texture.
height
intThe height of the texture.
depth
intThe depth of the texture.
mipLevels
MipMapCountA 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
width
int
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
mipmap
intThe 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
arrayOrZSliceIndex
intFor 3D image, the parameter is the Z slice, otherwise it is an index into the texture array.
mipmap
intThe 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
arrayIndex
intIndex into the texture array. Must be set to 0 for 3D images.
zIndex
intZ index for 3D image. Must be set to 0 for all 1D/2D images.
mipmap
intThe 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.
public static Image Load(DataPointer dataBuffer, bool makeACopy = false, bool loadAsSRGB = false)
Parameters
dataBuffer
DataPointerPointer to an unmanaged memory. If
makeACopy
is false, this buffer must be allocated with AllocateMemory(int, int).makeACopy
boolTrue to copy the content of the buffer to a new allocated buffer, false otherwise.
loadAsSRGB
boolIndicate 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
buffer
byte[]Reference to a managed buffer.
loadAsSRGB
boolIndicate 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
imageStream
StreamThe image stream.
loadAsSRGB
boolIndicate 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
dataPointer
nintPointer to an unmanaged memory. If
makeACopy
is false, this buffer must be allocated with AllocateMemory(int, int).dataSize
intSize of the unmanaged buffer.
makeACopy
boolTrue to copy the content of the buffer to a new allocated buffer, false otherwise.
loadAsSRGB
boolIndicate 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
description
ImageDescriptionThe 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
description
ImageDescriptionThe image description.
dataPointer
nintPointer 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
description
ImageDescriptionThe image description.
dataPointer
nintThe pointer to the data buffer.
offset
intThe offset from the beginning of the data buffer.
handle
GCHandle?The handle (optionnal).
bufferIsDisposable
boolif 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
width
intThe width.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe format.
arraySize
intSize 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
width
intThe width.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe format.
arraySize
intSize of the array.
dataPointer
nintPointer 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
width
intThe width.
height
intThe height.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe format.
arraySize
intSize of the array.
rowStride
int
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
width
intThe width.
height
intThe height.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe format.
arraySize
intSize of the array.
dataPointer
nintPointer to an existing buffer.
rowStride
intSpecify 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
width
intThe width.
height
intThe height.
depth
intThe depth.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe 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
width
intThe width.
height
intThe height.
depth
intThe depth.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe format.
dataPointer
nintPointer 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
width
intThe width.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe 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
width
intThe width.
mipMapCount
MipMapCountThe mip map count.
format
PixelFormatThe format.
dataPointer
nintPointer 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
type
ImageFileTypeThe file type (use integer and explicit casting to ImageFileType to register other fileformat.
loader
Image.ImageLoadDelegateThe loader delegate (can be null).
saver
Image.ImageSaveDelegateThe saver delegate (can be null).
Exceptions
Save(Stream, ImageFileType)
Saves this instance 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
.
ToDataBox()
Gets the databox from this image.
public DataBox[] ToDataBox()
Returns
- DataBox[]
The databox of this image.