Class Image
- Namespace
- SixLabors.ImageSharp
- Assembly
- SixLabors.ImageSharp.dll
Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. For the non-generic Image type, the pixel type is only known at runtime. Image is always implemented by a pixel-specific Image<TPixel> instance.
public abstract class Image : IDisposable, IConfigurationProvider
- Inheritance
-
Image
- Implements
- Derived
-
Image<TPixel>
- Inherited Members
- Extension Methods
Constructors
Image(Configuration, PixelTypeInfo, ImageMetadata, Size)
Initializes a new instance of the Image class.
protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size)
Parameters
configurationConfigurationThe global configuration..
pixelTypePixelTypeInfoThe pixel type information.
metadataImageMetadataThe image metadata.
sizeSizeThe size in px units.
Properties
Bounds
Gets the bounds of the image.
public Rectangle Bounds { get; }
Property Value
Configuration
public Configuration Configuration { get; }
Property Value
Frames
Gets the frames of the image as (non-generic) ImageFrameCollection.
public ImageFrameCollection Frames { get; }
Property Value
Height
Gets the image height in px units.
public int Height { get; }
Property Value
Metadata
Gets any metadata associated with the image.
public ImageMetadata Metadata { get; }
Property Value
NonGenericFrameCollection
Gets the ImageFrameCollection implementing the public Frames property.
protected abstract ImageFrameCollection NonGenericFrameCollection { get; }
Property Value
PixelType
Gets information about the image pixels.
public PixelTypeInfo PixelType { get; }
Property Value
Size
Gets the size of the image in px units.
public Size Size { get; }
Property Value
Width
Gets the image width in px units.
public int Width { get; }
Property Value
Methods
CloneAs<TPixel2>()
Returns a copy of the image in the given pixel format.
public Image<TPixel2> CloneAs<TPixel2>() where TPixel2 : unmanaged, IPixel<TPixel2>
Returns
- Image<TPixel2>
The Image<TPixel>
Type Parameters
TPixel2The pixel format.
CloneAs<TPixel2>(Configuration)
Returns a copy of the image in the given pixel format.
public abstract Image<TPixel2> CloneAs<TPixel2>(Configuration configuration) where TPixel2 : unmanaged, IPixel<TPixel2>
Parameters
configurationConfigurationThe configuration providing initialization code which allows extending the library.
Returns
- Image<TPixel2>
The Image<TPixel>.
Type Parameters
TPixel2The pixel format.
DetectFormat(DecoderOptions, Stream)
Detects the encoded image format type from the specified stream.
public static IImageFormat DetectFormat(DecoderOptions options, Stream stream)
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe image stream to read the header from.
Returns
- IImageFormat
The IImageFormat.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormat(DecoderOptions, ReadOnlySpan<byte>)
By reading the header on the provided byte span this calculates the images format.
public static IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan<byte> buffer)
Parameters
optionsDecoderOptionsThe general decoder options.
bufferReadOnlySpan<byte>The byte span containing encoded image data to read the header from.
Returns
- IImageFormat
The IImageFormat.
Exceptions
- ArgumentNullException
The options are null.
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormat(DecoderOptions, string)
Detects the encoded image format type from the specified file.
public static IImageFormat DetectFormat(DecoderOptions options, string path)
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe image file to open and to read the header from.
Returns
- IImageFormat
The IImageFormat.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormat(Stream)
Detects the encoded image format type from the specified stream.
public static IImageFormat DetectFormat(Stream stream)
Parameters
streamStreamThe image stream to read the header from.
Returns
- IImageFormat
The IImageFormat.
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormat(ReadOnlySpan<byte>)
By reading the header on the provided byte span this calculates the images format.
public static IImageFormat DetectFormat(ReadOnlySpan<byte> buffer)
Parameters
bufferReadOnlySpan<byte>The byte span containing encoded image data to read the header from.
Returns
- IImageFormat
The IImageFormat.
Exceptions
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormat(string)
Detects the encoded image format type from the specified file.
public static IImageFormat DetectFormat(string path)
Parameters
pathstringThe image file to open and to read the header from.
Returns
- IImageFormat
The IImageFormat.
Exceptions
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormatAsync(DecoderOptions, Stream, CancellationToken)
Detects the encoded image format type from the specified stream.
public static Task<IImageFormat> DetectFormatAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe image stream to read the header from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<IImageFormat>
A Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormatAsync(DecoderOptions, string, CancellationToken)
Detects the encoded image format type from the specified file.
public static Task<IImageFormat> DetectFormatAsync(DecoderOptions options, string path, CancellationToken cancellationToken = default)
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe image file to open and to read the header from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<IImageFormat>
A Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormatAsync(Stream, CancellationToken)
Detects the encoded image format type from the specified stream.
public static Task<IImageFormat> DetectFormatAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe image stream to read the header from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<IImageFormat>
A Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
DetectFormatAsync(string, CancellationToken)
Detects the encoded image format type from the specified file.
public static Task<IImageFormat> DetectFormatAsync(string path, CancellationToken cancellationToken = default)
Parameters
pathstringThe image file to open and to read the header from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<IImageFormat>
A Task<TResult> representing the asynchronous operation.
Dispose()
public void Dispose()
Dispose(bool)
Disposes the object and frees resources for the Garbage Collector.
protected abstract void Dispose(bool disposing)
Parameters
disposingboolWhether to dispose of managed and unmanaged objects.
Identify(DecoderOptions, Stream)
Reads the raw image information from the specified stream without fully decoding it.
public static ImageInfo Identify(DecoderOptions options, Stream stream)
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe image stream to read the information from.
Returns
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Identify(DecoderOptions, ReadOnlySpan<byte>)
Reads the raw image information from the specified span of bytes without fully decoding it.
public static ImageInfo Identify(DecoderOptions options, ReadOnlySpan<byte> buffer)
Parameters
optionsDecoderOptionsThe general decoder options.
bufferReadOnlySpan<byte>The byte span containing encoded image data to read the header from.
Returns
Exceptions
- ArgumentNullException
The options are null.
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Identify(DecoderOptions, string)
Reads the raw image information from the specified file path without fully decoding it.
public static ImageInfo Identify(DecoderOptions options, string path)
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe image file to open and to read the header from.
Returns
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Identify(Stream)
Reads the raw image information from the specified stream without fully decoding it.
public static ImageInfo Identify(Stream stream)
Parameters
streamStreamThe image stream to read the header from.
Returns
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Identify(ReadOnlySpan<byte>)
Reads the raw image information from the specified stream without fully decoding it.
public static ImageInfo Identify(ReadOnlySpan<byte> buffer)
Parameters
bufferReadOnlySpan<byte>The byte array containing encoded image data to read the header from.
Returns
Exceptions
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Identify(string)
Reads the raw image information from the specified file path without fully decoding it. A return value indicates whether the operation succeeded.
public static ImageInfo Identify(string path)
Parameters
pathstringThe image file to open and to read the header from.
Returns
Exceptions
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
IdentifyAsync(DecoderOptions, Stream, CancellationToken)
Reads the raw image information from the specified stream without fully decoding it.
public static Task<ImageInfo> IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe image stream to read the information from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ImageInfo>
The Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
IdentifyAsync(DecoderOptions, string, CancellationToken)
Reads the raw image information from the specified stream without fully decoding it.
public static Task<ImageInfo> IdentifyAsync(DecoderOptions options, string path, CancellationToken cancellationToken = default)
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe image file to open and to read the header from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ImageInfo>
The Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
IdentifyAsync(Stream, CancellationToken)
Reads the raw image information from the specified stream without fully decoding it.
public static Task<ImageInfo> IdentifyAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe image stream to read the information from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ImageInfo>
The Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
IdentifyAsync(string, CancellationToken)
Reads the raw image information from the specified stream without fully decoding it.
public static Task<ImageInfo> IdentifyAsync(string path, CancellationToken cancellationToken = default)
Parameters
pathstringThe image file to open and to read the header from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<ImageInfo>
The Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load(DecoderOptions, Stream)
Creates a new instance of the Image class from the given stream. The pixel format is automatically determined by the decoder.
public static Image Load(DecoderOptions options, Stream stream)
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe stream containing image information.
Returns
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load(DecoderOptions, ReadOnlySpan<byte>)
Creates a new instance of the Image class from the given byte span. The pixel format is automatically determined by the decoder.
public static Image Load(DecoderOptions options, ReadOnlySpan<byte> buffer)
Parameters
optionsDecoderOptionsThe general decoder options.
bufferReadOnlySpan<byte>The byte span containing encoded image data.
Returns
Exceptions
- ArgumentNullException
The options are null.
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load(DecoderOptions, string)
Creates a new instance of the Image class from the given file path. The pixel format is automatically determined by the decoder.
public static Image Load(DecoderOptions options, string path)
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe file path to the image.
Returns
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load(Stream)
Creates a new instance of the Image class from the given stream. The pixel format is automatically determined by the decoder.
public static Image Load(Stream stream)
Parameters
streamStreamThe stream containing image information.
Returns
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load(ReadOnlySpan<byte>)
Creates a new instance of the Image class from the given byte span. The pixel format is automatically determined by the decoder.
public static Image Load(ReadOnlySpan<byte> buffer)
Parameters
bufferReadOnlySpan<byte>The byte span containing encoded image data.
Returns
Exceptions
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load(string)
Creates a new instance of the Image class from the given file path. The pixel format is automatically determined by the decoder.
public static Image Load(string path)
Parameters
pathstringThe file path to the image.
Returns
Exceptions
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync(DecoderOptions, Stream, CancellationToken)
Creates a new instance of the Image class from the given stream. The pixel format is automatically determined by the decoder.
public static Task<Image> LoadAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe stream containing image information.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image>
A Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync(DecoderOptions, string, CancellationToken)
Creates a new instance of the Image class from the given file path. The pixel format is automatically determined by the decoder.
public static Task<Image> LoadAsync(DecoderOptions options, string path, CancellationToken cancellationToken = default)
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe file path to the image.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image>
A Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync(Stream, CancellationToken)
Creates a new instance of the Image class from the given stream. The pixel format is automatically determined by the decoder.
public static Task<Image> LoadAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream containing image information.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image>
A Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync(string, CancellationToken)
Creates a new instance of the Image class from the given file path. The pixel format is automatically determined by the decoder.
public static Task<Image> LoadAsync(string path, CancellationToken cancellationToken = default)
Parameters
pathstringThe file path to the image.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image>
A Task<TResult> representing the asynchronous operation.
Exceptions
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync<TPixel>(DecoderOptions, Stream, CancellationToken)
Creates a new instance of the Image<TPixel> class from the given stream.
public static Task<Image<TPixel>> LoadAsync<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe stream containing image information.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image<TPixel>>
A Task<TResult> representing the asynchronous operation.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync<TPixel>(DecoderOptions, string, CancellationToken)
Creates a new instance of the Image<TPixel> class from the given file path.
public static Task<Image<TPixel>> LoadAsync<TPixel>(DecoderOptions options, string path, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe file path to the image.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image<TPixel>>
A Task<TResult> representing the asynchronous operation.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync<TPixel>(Stream, CancellationToken)
Creates a new instance of the Image<TPixel> class from the given stream.
public static Task<Image<TPixel>> LoadAsync<TPixel>(Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
streamStreamThe stream containing image information.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image<TPixel>>
A Task<TResult> representing the asynchronous operation.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadAsync<TPixel>(string, CancellationToken)
Creates a new instance of the Image<TPixel> class from the given file path.
public static Task<Image<TPixel>> LoadAsync<TPixel>(string path, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
pathstringThe file path to the image.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<Image<TPixel>>
A Task<TResult> representing the asynchronous operation.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
LoadPixelData<TPixel>(Configuration, ReadOnlySpan<byte>, int, int)
Create a new instance of the Image<TPixel> class from the given readonly span of bytes in TPixel format.
public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, ReadOnlySpan<byte> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe configuration for the decoder.
dataReadOnlySpan<byte>The readonly span of bytes containing image data.
widthintThe width of the final image.
heightintThe height of the final image.
Returns
- Image<TPixel>
A new Image<TPixel>.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The configuration is null.
- ArgumentException
The data length is incorrect.
LoadPixelData<TPixel>(Configuration, ReadOnlySpan<TPixel>, int, int)
Create a new instance of the Image<TPixel> class from the raw TPixel data.
public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, ReadOnlySpan<TPixel> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe configuration for the decoder.
dataReadOnlySpan<TPixel>The readonly span containing the image pixel data.
widthintThe width of the final image.
heightintThe height of the final image.
Returns
- Image<TPixel>
A new Image<TPixel>.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The configuration is null.
- ArgumentException
The data length is incorrect.
LoadPixelData<TPixel>(ReadOnlySpan<byte>, int, int)
Create a new instance of the Image<TPixel> class from the given readonly span of bytes in TPixel format.
public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<byte> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
dataReadOnlySpan<byte>The readonly span of bytes containing image data.
widthintThe width of the final image.
heightintThe height of the final image.
Returns
- Image<TPixel>
A new Image<TPixel>.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentException
The data length is incorrect.
LoadPixelData<TPixel>(ReadOnlySpan<TPixel>, int, int)
Create a new instance of the Image<TPixel> class from the raw TPixel data.
public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<TPixel> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
dataReadOnlySpan<TPixel>The readonly span of bytes containing image data.
widthintThe width of the final image.
heightintThe height of the final image.
Returns
- Image<TPixel>
A new Image<TPixel>.
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentException
The data length is incorrect.
Load<TPixel>(DecoderOptions, Stream)
Creates a new instance of the Image<TPixel> class from the given stream.
public static Image<TPixel> Load<TPixel>(DecoderOptions options, Stream stream) where TPixel : unmanaged, IPixel<TPixel>
Parameters
optionsDecoderOptionsThe general decoder options.
streamStreamThe stream containing image information.
Returns
- Image<TPixel>
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load<TPixel>(DecoderOptions, ReadOnlySpan<byte>)
Creates a new instance of the Image<TPixel> class from the given byte span.
public static Image<TPixel> Load<TPixel>(DecoderOptions options, ReadOnlySpan<byte> data) where TPixel : unmanaged, IPixel<TPixel>
Parameters
optionsDecoderOptionsThe general decoder options.
dataReadOnlySpan<byte>The byte span containing encoded image data.
Returns
- Image<TPixel>
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The options are null.
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load<TPixel>(DecoderOptions, string)
Creates a new instance of the Image<TPixel> class from the given file path.
public static Image<TPixel> Load<TPixel>(DecoderOptions options, string path) where TPixel : unmanaged, IPixel<TPixel>
Parameters
optionsDecoderOptionsThe general decoder options.
pathstringThe file path to the image.
Returns
- Image<TPixel>
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The options are null.
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load<TPixel>(Stream)
Creates a new instance of the Image<TPixel> class from the given stream.
public static Image<TPixel> Load<TPixel>(Stream stream) where TPixel : unmanaged, IPixel<TPixel>
Parameters
streamStreamThe stream containing image information.
Returns
- Image<TPixel>
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The stream is null.
- NotSupportedException
The stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load<TPixel>(ReadOnlySpan<byte>)
Creates a new instance of the Image<TPixel> class from the given byte span.
public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data) where TPixel : unmanaged, IPixel<TPixel>
Parameters
dataReadOnlySpan<byte>The byte span containing encoded image data.
Returns
- Image<TPixel>
Type Parameters
TPixelThe pixel format.
Exceptions
- NotSupportedException
The image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Load<TPixel>(string)
Creates a new instance of the Image<TPixel> class from the given file path.
public static Image<TPixel> Load<TPixel>(string path) where TPixel : unmanaged, IPixel<TPixel>
Parameters
pathstringThe file path to the image.
Returns
- Image<TPixel>
Type Parameters
TPixelThe pixel format.
Exceptions
- ArgumentNullException
The path is null.
- NotSupportedException
The file stream is not readable or the image format is not supported.
- InvalidImageContentException
The encoded image contains invalid content.
- UnknownImageFormatException
The encoded image format is unknown.
Save(Stream, IImageEncoder)
Saves the image to the given stream using the given image encoder.
public void Save(Stream stream, IImageEncoder encoder)
Parameters
streamStreamThe stream to save the image to.
encoderIImageEncoderThe encoder to save the image with.
Exceptions
- ArgumentNullException
Thrown if the stream or encoder is null.
SaveAsync(Stream, IImageEncoder, CancellationToken)
Saves the image to the given stream using the given image encoder.
public Task SaveAsync(Stream stream, IImageEncoder encoder, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream to save the image to.
encoderIImageEncoderThe encoder to save the image with.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
Exceptions
- ArgumentNullException
Thrown if the stream or encoder is null.
UpdateSize(Size)
Update the size of the image after mutation.
protected void UpdateSize(Size size)
Parameters
WrapMemory<TPixel>(Configuration, IMemoryOwner<byte>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels,
allowing to view/manipulate it as an Image<TPixel> instance.
The ownership of the byteMemoryOwner is being transferred to the new Image<TPixel> instance,
meaning that the caller is not allowed to dispose byteMemoryOwner.
It will be disposed together with the result image.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<byte> byteMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
byteMemoryOwnerIMemoryOwner<byte>The IMemoryOwner<T> that is being transferred to the image.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance
Type Parameters
TPixelThe pixel type.
Exceptions
- ArgumentNullException
The configuration is null.
WrapMemory<TPixel>(Configuration, IMemoryOwner<byte>, int, int, ImageMetadata)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels,
allowing to view/manipulate it as an Image<TPixel> instance.
The ownership of the byteMemoryOwner is being transferred to the new Image<TPixel> instance,
meaning that the caller is not allowed to dispose byteMemoryOwner.
It will be disposed together with the result image.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<byte> byteMemoryOwner, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
byteMemoryOwnerIMemoryOwner<byte>The IMemoryOwner<T> that is being transferred to the image
widthintThe width of the memory image.
heightintThe height of the memory image.
metadataImageMetadataThe ImageMetadata
Returns
- Image<TPixel>
An Image<TPixel> instance
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
- ArgumentNullException
The metadata is null.
WrapMemory<TPixel>(Configuration, IMemoryOwner<TPixel>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels,
allowing to view/manipulate it as an Image<TPixel> instance.
The ownership of the pixelMemoryOwner is being transferred to the new Image<TPixel> instance,
meaning that the caller is not allowed to dispose pixelMemoryOwner.
It will be disposed together with the result image.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<TPixel> pixelMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
pixelMemoryOwnerIMemoryOwner<TPixel>The IMemoryOwner<T> that is being transferred to the image.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance
Type Parameters
TPixelThe pixel type.
Exceptions
- ArgumentNullException
The configuration is null.
WrapMemory<TPixel>(Configuration, IMemoryOwner<TPixel>, int, int, ImageMetadata)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels,
allowing to view/manipulate it as an Image<TPixel> instance.
The ownership of the pixelMemoryOwner is being transferred to the new Image<TPixel> instance,
meaning that the caller is not allowed to dispose pixelMemoryOwner.
It will be disposed together with the result image.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<TPixel> pixelMemoryOwner, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
pixelMemoryOwnerIMemoryOwner<TPixel>The IMemoryOwner<T> that is being transferred to the image
widthintThe width of the memory image.
heightintThe height of the memory image.
metadataImageMetadataThe ImageMetadata
Returns
- Image<TPixel>
An Image<TPixel> instance
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
- ArgumentNullException
The metadata is null.
WrapMemory<TPixel>(Configuration, Memory<byte>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: using this method does not transfer the ownership of the underlying buffer of the input Memory<T> to the new Image<TPixel> instance. This means that consumers of this method must ensure that the input buffer is either self-contained, (for example, a Memory<T> instance wrapping a new array that was created), or that the owning object is not disposed until the returned Image<TPixel> is disposed.
If the input Memory<T> instance is one retrieved from an IMemoryOwner<T> instance rented from a memory pool (such as MemoryPool<T>), and that owning instance is disposed while the image is still in use, this will lead to undefined behavior and possibly runtime crashes (as the same buffer might then be modified by other consumers while the returned image is still working on it). Make sure to control the lifetime of the input buffers appropriately.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<byte> byteMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
byteMemoryMemory<byte>The byte memory representing the pixel data.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
WrapMemory<TPixel>(Configuration, Memory<byte>, int, int, ImageMetadata)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: using this method does not transfer the ownership of the underlying buffer of the input Memory<T> to the new Image<TPixel> instance. This means that consumers of this method must ensure that the input buffer is either self-contained, (for example, a Memory<T> instance wrapping a new array that was created), or that the owning object is not disposed until the returned Image<TPixel> is disposed.
If the input Memory<T> instance is one retrieved from an IMemoryOwner<T> instance rented from a memory pool (such as MemoryPool<T>), and that owning instance is disposed while the image is still in use, this will lead to undefined behavior and possibly runtime crashes (as the same buffer might then be modified by other consumers while the returned image is still working on it). Make sure to control the lifetime of the input buffers appropriately.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<byte> byteMemory, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
byteMemoryMemory<byte>The byte memory representing the pixel data.
widthintThe width of the memory image.
heightintThe height of the memory image.
metadataImageMetadataThe ImageMetadata.
Returns
- Image<TPixel>
An Image<TPixel> instance
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
- ArgumentNullException
The metadata is null.
WrapMemory<TPixel>(Configuration, Memory<TPixel>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: using this method does not transfer the ownership of the underlying buffer of the input Memory<T> to the new Image<TPixel> instance. This means that consumers of this method must ensure that the input buffer is either self-contained, (for example, a Memory<T> instance wrapping a new array that was created), or that the owning object is not disposed until the returned Image<TPixel> is disposed.
If the input Memory<T> instance is one retrieved from an IMemoryOwner<T> instance rented from a memory pool (such as MemoryPool<T>), and that owning instance is disposed while the image is still in use, this will lead to undefined behavior and possibly runtime crashes (as the same buffer might then be modified by other consumers while the returned image is still working on it). Make sure to control the lifetime of the input buffers appropriately.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<TPixel> pixelMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
pixelMemoryMemory<TPixel>The pixel memory.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
WrapMemory<TPixel>(Configuration, Memory<TPixel>, int, int, ImageMetadata)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: using this method does not transfer the ownership of the underlying buffer of the input Memory<T> to the new Image<TPixel> instance. This means that consumers of this method must ensure that the input buffer is either self-contained, (for example, a Memory<T> instance wrapping a new array that was created), or that the owning object is not disposed until the returned Image<TPixel> is disposed.
If the input Memory<T> instance is one retrieved from an IMemoryOwner<T> instance rented from a memory pool (such as MemoryPool<T>), and that owning instance is disposed while the image is still in use, this will lead to undefined behavior and possibly runtime crashes (as the same buffer might then be modified by other consumers while the returned image is still working on it). Make sure to control the lifetime of the input buffers appropriately.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<TPixel> pixelMemory, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
pixelMemoryMemory<TPixel>The pixel memory.
widthintThe width of the memory image.
heightintThe height of the memory image.
metadataImageMetadataThe ImageMetadata.
Returns
- Image<TPixel>
An Image<TPixel> instance
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
- ArgumentNullException
The metadata is null.
WrapMemory<TPixel>(Configuration, void*, int, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: this method relies on callers to carefully manage the target memory area being referenced by the pointer and that the lifetime of such a memory area is at least equal to that of the returned Image<TPixel> instance. For example, if the input pointer references an unmanaged memory area, callers must ensure that the memory area is not freed as long as the returned Image<TPixel> is in use and not disposed. The same applies if the input memory area points to a pinned managed object, as callers must ensure that objects will remain pinned as long as the Image<TPixel> instance is in use. Failing to do so constitutes undefined behavior and will likely lead to memory corruption and runtime crashes.
Note also that if you have a Memory<T> or an array (which can be cast to Memory<T>) of
either byte or TPixel values, it is highly recommended to use one of the other
available overloads of this method instead (such as WrapMemory<TPixel>(Configuration, Memory<byte>, int, int)
or WrapMemory<TPixel>(Configuration, Memory<TPixel>, int, int), to make the resulting code less error
prone and avoid having to pin the underlying memory buffer in use. This method is primarily meant to be used when
doing interop or working with buffers that are located in unmanaged memory.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, void* pointer, int bufferSizeInBytes, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
pointervoid*The pointer to the target memory buffer to wrap.
bufferSizeInBytesintThe byte length of the memory allocated.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
WrapMemory<TPixel>(Configuration, void*, int, int, int, ImageMetadata)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: this method relies on callers to carefully manage the target memory area being referenced by the pointer and that the lifetime of such a memory area is at least equal to that of the returned Image<TPixel> instance. For example, if the input pointer references an unmanaged memory area, callers must ensure that the memory area is not freed as long as the returned Image<TPixel> is in use and not disposed. The same applies if the input memory area points to a pinned managed object, as callers must ensure that objects will remain pinned as long as the Image<TPixel> instance is in use. Failing to do so constitutes undefined behavior and will likely lead to memory corruption and runtime crashes.
Note also that if you have a Memory<T> or an array (which can be cast to Memory<T>) of
either byte or TPixel values, it is highly recommended to use one of the other
available overloads of this method instead (such as WrapMemory<TPixel>(Configuration, Memory<byte>, int, int)
or WrapMemory<TPixel>(Configuration, Memory<TPixel>, int, int), to make the resulting code less error
prone and avoid having to pin the underlying memory buffer in use. This method is primarily meant to be used when
doing interop or working with buffers that are located in unmanaged memory.
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, void* pointer, int bufferSizeInBytes, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
configurationConfigurationThe Configuration
pointervoid*The pointer to the target memory buffer to wrap.
bufferSizeInBytesintThe byte length of the memory allocated.
widthintThe width of the memory image.
heightintThe height of the memory image.
metadataImageMetadataThe ImageMetadata.
Returns
- Image<TPixel>
An Image<TPixel> instance
Type Parameters
TPixelThe pixel type
Exceptions
- ArgumentNullException
The configuration is null.
- ArgumentNullException
The metadata is null.
WrapMemory<TPixel>(IMemoryOwner<byte>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels,
allowing to view/manipulate it as an Image<TPixel> instance.
The ownership of the byteMemoryOwner is being transferred to the new Image<TPixel> instance,
meaning that the caller is not allowed to dispose byteMemoryOwner.
It will be disposed together with the result image.
public static Image<TPixel> WrapMemory<TPixel>(IMemoryOwner<byte> byteMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
byteMemoryOwnerIMemoryOwner<byte>The IMemoryOwner<T> that is being transferred to the image.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type
WrapMemory<TPixel>(IMemoryOwner<TPixel>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels,
allowing to view/manipulate it as an Image<TPixel> instance.
The ownership of the pixelMemoryOwner is being transferred to the new Image<TPixel> instance,
meaning that the caller is not allowed to dispose pixelMemoryOwner.
It will be disposed together with the result image.
public static Image<TPixel> WrapMemory<TPixel>(IMemoryOwner<TPixel> pixelMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
pixelMemoryOwnerIMemoryOwner<TPixel>The IMemoryOwner<T> that is being transferred to the image.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type
WrapMemory<TPixel>(Memory<byte>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: using this method does not transfer the ownership of the underlying buffer of the input Memory<T> to the new Image<TPixel> instance. This means that consumers of this method must ensure that the input buffer is either self-contained, (for example, a Memory<T> instance wrapping a new array that was created), or that the owning object is not disposed until the returned Image<TPixel> is disposed.
If the input Memory<T> instance is one retrieved from an IMemoryOwner<T> instance rented from a memory pool (such as MemoryPool<T>), and that owning instance is disposed while the image is still in use, this will lead to undefined behavior and possibly runtime crashes (as the same buffer might then be modified by other consumers while the returned image is still working on it). Make sure to control the lifetime of the input buffers appropriately.
public static Image<TPixel> WrapMemory<TPixel>(Memory<byte> byteMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
byteMemoryMemory<byte>The byte memory representing the pixel data.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type.
WrapMemory<TPixel>(Memory<TPixel>, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: using this method does not transfer the ownership of the underlying buffer of the input Memory<T> to the new Image<TPixel> instance. This means that consumers of this method must ensure that the input buffer is either self-contained, (for example, a Memory<T> instance wrapping a new array that was created), or that the owning object is not disposed until the returned Image<TPixel> is disposed.
If the input Memory<T> instance is one retrieved from an IMemoryOwner<T> instance rented from a memory pool (such as MemoryPool<T>), and that owning instance is disposed while the image is still in use, this will lead to undefined behavior and possibly runtime crashes (as the same buffer might then be modified by other consumers while the returned image is still working on it). Make sure to control the lifetime of the input buffers appropriately.
public static Image<TPixel> WrapMemory<TPixel>(Memory<TPixel> pixelMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
pixelMemoryMemory<TPixel>The pixel memory.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type.
WrapMemory<TPixel>(void*, int, int, int)
Wraps an existing contiguous memory area of at least 'width' x 'height' pixels allowing viewing/manipulation as an Image<TPixel> instance.
Please note: this method relies on callers to carefully manage the target memory area being referenced by the pointer and that the lifetime of such a memory area is at least equal to that of the returned Image<TPixel> instance. For example, if the input pointer references an unmanaged memory area, callers must ensure that the memory area is not freed as long as the returned Image<TPixel> is in use and not disposed. The same applies if the input memory area points to a pinned managed object, as callers must ensure that objects will remain pinned as long as the Image<TPixel> instance is in use. Failing to do so constitutes undefined behavior and will likely lead to memory corruption and runtime crashes.
Note also that if you have a Memory<T> or an array (which can be cast to Memory<T>) of
either byte or TPixel values, it is highly recommended to use one of the other
available overloads of this method instead (such as WrapMemory<TPixel>(Configuration, Memory<byte>, int, int)
or WrapMemory<TPixel>(Configuration, Memory<TPixel>, int, int), to make the resulting code less error
prone and avoid having to pin the underlying memory buffer in use. This method is primarily meant to be used when
doing interop or working with buffers that are located in unmanaged memory.
public static Image<TPixel> WrapMemory<TPixel>(void* pointer, int bufferSizeInBytes, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
pointervoid*The pointer to the target memory buffer to wrap.
bufferSizeInBytesintThe byte length of the memory allocated.
widthintThe width of the memory image.
heightintThe height of the memory image.
Returns
- Image<TPixel>
An Image<TPixel> instance.
Type Parameters
TPixelThe pixel type.