Table of Contents

Class Image

Namespace
SharpDX.Toolkit.Graphics
Assembly
HelixToolkit.SharpDX.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.

public sealed class Image : Component, IComponent, INotifyPropertyChanged, IDisposable
Inheritance
Image
Implements
Inherited Members

Fields

Description

Description of this image.

public ImageDescription Description

Field Value

ImageDescription

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

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

int

Methods

Dispose(bool)

protected override void Dispose(bool disposeManagedResources)

Parameters

disposeManagedResources bool

GetMipMapDescription(int)

Gets the mipmap description of this instance for the specified mipmap level.

public MipMapDescription GetMipMapDescription(int mipmap)

Parameters

mipmap int

The 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 int

For 3D image, the parameter is the Z slice, otherwise it is an index into the texture array.

mipmap int

The mipmap.

Returns

PixelBuffer

A PixelBufferArray.

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 int

Index into the texture array. Must be set to 0 for 3D images.

zIndex int

Z index for 3D image. Must be set to 0 for all 1D/2D images.

mipmap int

The mipmap.

Returns

PixelBuffer

A PixelBufferArray.

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

dataBuffer DataPointer

Pointer to an unmanaged memory. If makeACopy is false, this buffer must be allocated with AllocateMemory(int, int).

makeACopy bool

True 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

buffer byte[]

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

imageStream Stream

The 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

dataPointer nint

Pointer to an unmanaged memory. If makeACopy is false, this buffer must be allocated with AllocateMemory(int, int).

dataSize int

Size of the unmanaged buffer.

makeACopy bool

True 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

fileName string

The 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

description ImageDescription

The 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 ImageDescription

The image description.

dataPointer nint

Pointer 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

width int

The width.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The format.

arraySize int

Size 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 int

The width.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The format.

arraySize int

Size of the array.

dataPointer nint

Pointer 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

width int

The width.

height int

The height.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The format.

arraySize int

Size 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

width int

The width.

height int

The height.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The format.

arraySize int

Size of the array.

dataPointer nint

Pointer 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

width int

The width.

height int

The height.

depth int

The depth.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The 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 int

The width.

height int

The height.

depth int

The depth.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The format.

dataPointer nint

Pointer 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 int

The width.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The 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 int

The width.

mipMapCount MipMapCount

The mip map count.

format PixelFormat

The format.

dataPointer nint

Pointer 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 ImageFileType

The file type (use integer and explicit casting to ImageFileType to register other file format.

loader Image.ImageLoadDelegate

The loader delegate (can be null).

saver Image.ImageSaveDelegate

The saver delegate (can be null).

Exceptions

ArgumentException

Save(Stream, ImageFileType)

Saves this instance to a stream.

public void Save(Stream imageStream, ImageFileType fileType)

Parameters

imageStream Stream

The destination stream.

fileType ImageFileType

Specify 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

fileName string

The 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

fileName string

The destination file.

fileType ImageFileType

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

DataBox[]

The databox of this image.