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.
public sealed class Image : Component, IComponent, INotifyPropertyChanged, IDisposable
- Inheritance
-
Image
- Implements
- Inherited Members
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
Dispose(bool)
protected override void Dispose(bool disposeManagedResources)
Parameters
disposeManagedResourcesbool
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)
Loads an image from an unmanaged memory pointer.
public static Image? Load(DataPointer dataBuffer, bool makeACopy = 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 otherwhise.
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[])
Loads an image from a managed buffer.
public static Image? Load(byte[] buffer)
Parameters
bufferbyte[]Reference to a managed buffer.
Returns
- Image
An new image.
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga.
Load(Stream)
Loads the specified image from a stream.
public static Image? Load(Stream imageStream)
Parameters
imageStreamStreamThe image stream.
Returns
- Image
An new image.
Remarks
This method support the following format: dds, bmp, jpg, png, gif, tiff, wmp, tga.
Load(nint, int, bool)
Loads an image from an unmanaged memory pointer.
public static Image? Load(nint dataPointer, int dataSize, bool makeACopy = 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.
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(string)
Loads the specified image from a file.
public static Image? Load(string fileName)
Parameters
fileNamestringThe filename.
Returns
- 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
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.
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)
Creates a new instance of a 2D Image.
public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize = 1)
Parameters
widthintThe width.
heightintThe height.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
arraySizeintSize of the array.
Returns
- Image
A new image.
New2D(int, int, MipMapCount, PixelFormat, int, nint)
Creates a new instance of a 2D Image.
public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize, nint dataPointer)
Parameters
widthintThe width.
heightintThe height.
mipMapCountMipMapCountThe mip map count.
formatPixelFormatThe format.
arraySizeintSize of the array.
dataPointernintPointer to an existing buffer.
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 file format.
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.
Save(string)
Saves this instance to a file.
public void Save(string fileName)
Parameters
fileNamestringThe destination file. Filename must end with a known extension (dds, bmp, jpg, png, gif, tiff, wmp, tga)
Save(string, ImageFileType)
Saves this instance to a file.
public void Save(string fileName, ImageFileType fileType)
Parameters
fileNamestringThe destination file.
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.