Class Image
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.
Inherited Members
Namespace: SixLabors.ImageSharp
Assembly: SixLabors.ImageSharp.dll
Syntax
public abstract class Image : IDisposable, IConfigurationProvider
Constructors
| Edit this page View SourceImage(Configuration, PixelTypeInfo, ImageMetadata, Size)
Initializes a new instance of the Image class.
Declaration
protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The global configuration.. |
| PixelTypeInfo | pixelType | The pixel type information. |
| ImageMetadata | metadata | The image metadata. |
| Size | size | The size in px units. |
Properties
| Edit this page View SourceBounds
Gets the bounds of the image.
Declaration
public Rectangle Bounds { get; }
Property Value
| Type | Description |
|---|---|
| Rectangle |
Configuration
Gets the configuration which allows altering default behaviour or extending the library.
Declaration
public Configuration Configuration { get; }
Property Value
| Type | Description |
|---|---|
| Configuration |
Frames
Gets the frames of the image as (non-generic) ImageFrameCollection.
Declaration
public ImageFrameCollection Frames { get; }
Property Value
| Type | Description |
|---|---|
| ImageFrameCollection |
Height
Gets the image height in px units.
Declaration
public int Height { get; }
Property Value
| Type | Description |
|---|---|
| int |
Metadata
Gets any metadata associated with the image.
Declaration
public ImageMetadata Metadata { get; }
Property Value
| Type | Description |
|---|---|
| ImageMetadata |
NonGenericFrameCollection
Gets the ImageFrameCollection implementing the public Frames property.
Declaration
protected abstract ImageFrameCollection NonGenericFrameCollection { get; }
Property Value
| Type | Description |
|---|---|
| ImageFrameCollection |
PixelType
Gets information about the image pixels.
Declaration
public PixelTypeInfo PixelType { get; }
Property Value
| Type | Description |
|---|---|
| PixelTypeInfo |
Size
Gets the size of the image in px units.
Declaration
public Size Size { get; }
Property Value
| Type | Description |
|---|---|
| Size |
Width
Gets the image width in px units.
Declaration
public int Width { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
| Edit this page View SourceCloneAs<TPixel2>()
Returns a copy of the image in the given pixel format.
Declaration
public Image<TPixel2> CloneAs<TPixel2>() where TPixel2 : unmanaged, IPixel<TPixel2>
Returns
| Type | Description |
|---|---|
| Image<TPixel2> | The Image<TPixel> |
Type Parameters
| Name | Description |
|---|---|
| TPixel2 | The pixel format. |
CloneAs<TPixel2>(Configuration)
Returns a copy of the image in the given pixel format.
Declaration
public abstract Image<TPixel2> CloneAs<TPixel2>(Configuration configuration) where TPixel2 : unmanaged, IPixel<TPixel2>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The configuration providing initialization code which allows extending the library. |
Returns
| Type | Description |
|---|---|
| Image<TPixel2> | The Image<TPixel>. |
Type Parameters
| Name | Description |
|---|---|
| TPixel2 | The pixel format. |
DetectFormat(DecoderOptions, Stream)
Detects the encoded image format type from the specified stream.
Declaration
public static IImageFormat DetectFormat(DecoderOptions options, Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The image stream to read the header from. |
Returns
| Type | Description |
|---|---|
| IImageFormat | The IImageFormat. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| ReadOnlySpan<byte> | buffer | The byte span containing encoded image data to read the header from. |
Returns
| Type | Description |
|---|---|
| IImageFormat | The IImageFormat. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static IImageFormat DetectFormat(DecoderOptions options, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The image file to open and to read the header from. |
Returns
| Type | Description |
|---|---|
| IImageFormat | The IImageFormat. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static IImageFormat DetectFormat(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The image stream to read the header from. |
Returns
| Type | Description |
|---|---|
| IImageFormat | The IImageFormat. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static IImageFormat DetectFormat(ReadOnlySpan<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | buffer | The byte span containing encoded image data to read the header from. |
Returns
| Type | Description |
|---|---|
| IImageFormat | The IImageFormat. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static IImageFormat DetectFormat(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The image file to open and to read the header from. |
Returns
| Type | Description |
|---|---|
| IImageFormat | The IImageFormat. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<IImageFormat> DetectFormatAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The image stream to read the header from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<IImageFormat> | A Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<IImageFormat> DetectFormatAsync(DecoderOptions options, string path, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The image file to open and to read the header from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<IImageFormat> | A Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<IImageFormat> DetectFormatAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The image stream to read the header from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<IImageFormat> | A Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<IImageFormat> DetectFormatAsync(string path, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The image file to open and to read the header from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<IImageFormat> | A Task<TResult> representing the asynchronous operation. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Disposes the object and frees resources for the Garbage Collector.
Declaration
protected abstract void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | disposing | Whether to dispose of managed and unmanaged objects. |
Identify(DecoderOptions, Stream)
Reads the raw image information from the specified stream without fully decoding it.
Declaration
public static ImageInfo Identify(DecoderOptions options, Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The image stream to read the information from. |
Returns
| Type | Description |
|---|---|
| ImageInfo | The ImageInfo. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static ImageInfo Identify(DecoderOptions options, ReadOnlySpan<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| ReadOnlySpan<byte> | buffer | The byte span containing encoded image data to read the header from. |
Returns
| Type | Description |
|---|---|
| ImageInfo | The ImageInfo. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static ImageInfo Identify(DecoderOptions options, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The image file to open and to read the header from. |
Returns
| Type | Description |
|---|---|
| ImageInfo | The ImageInfo. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static ImageInfo Identify(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The image stream to read the header from. |
Returns
| Type | Description |
|---|---|
| ImageInfo | The ImageInfo. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static ImageInfo Identify(ReadOnlySpan<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | buffer | The byte array containing encoded image data to read the header from. |
Returns
| Type | Description |
|---|---|
| ImageInfo | The ImageInfo. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static ImageInfo Identify(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The image file to open and to read the header from. |
Returns
| Type | Description |
|---|---|
| ImageInfo | The ImageInfo. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<ImageInfo> IdentifyAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The image stream to read the information from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<ImageInfo> | The Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<ImageInfo> IdentifyAsync(DecoderOptions options, string path, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The image file to open and to read the header from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<ImageInfo> | The Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<ImageInfo> IdentifyAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The image stream to read the information from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<ImageInfo> | The Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<ImageInfo> IdentifyAsync(string path, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The image file to open and to read the header from. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<ImageInfo> | The Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image Load(DecoderOptions options, Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The stream containing image information. |
Returns
| Type | Description |
|---|---|
| Image |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image Load(DecoderOptions options, ReadOnlySpan<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| ReadOnlySpan<byte> | buffer | The byte span containing encoded image data. |
Returns
| Type | Description |
|---|---|
| Image |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image Load(DecoderOptions options, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The file path to the image. |
Returns
| Type | Description |
|---|---|
| Image |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image Load(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream containing image information. |
Returns
| Type | Description |
|---|---|
| Image |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image Load(ReadOnlySpan<byte> buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | buffer | The byte span containing encoded image data. |
Returns
| Type | Description |
|---|---|
| Image |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image Load(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file path to the image. |
Returns
| Type | Description |
|---|---|
| Image |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image> LoadAsync(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The stream containing image information. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image> | A Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image> LoadAsync(DecoderOptions options, string path, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The file path to the image. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image> | A Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image> LoadAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream containing image information. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image> | A Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image> LoadAsync(string path, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file path to the image. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image> | A Task<TResult> representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image<TPixel>> LoadAsync<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The stream containing image information. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image<TPixel>> | A Task<TResult> representing the asynchronous operation. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image<TPixel>> LoadAsync<TPixel>(DecoderOptions options, string path, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The file path to the image. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image<TPixel>> | A Task<TResult> representing the asynchronous operation. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image<TPixel>> LoadAsync<TPixel>(Stream stream, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream containing image information. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image<TPixel>> | A Task<TResult> representing the asynchronous operation. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Task<Image<TPixel>> LoadAsync<TPixel>(string path, CancellationToken cancellationToken = default) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file path to the image. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Image<TPixel>> | A Task<TResult> representing the asynchronous operation. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, ReadOnlySpan<byte> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The configuration for the decoder. |
| ReadOnlySpan<byte> | data | The readonly span of bytes containing image data. |
| int | width | The width of the final image. |
| int | height | The height of the final image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | A new Image<TPixel>. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> LoadPixelData<TPixel>(Configuration configuration, ReadOnlySpan<TPixel> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The configuration for the decoder. |
| ReadOnlySpan<TPixel> | data | The readonly span containing the image pixel data. |
| int | width | The width of the final image. |
| int | height | The height of the final image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | A new Image<TPixel>. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<byte> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The readonly span of bytes containing image data. |
| int | width | The width of the final image. |
| int | height | The height of the final image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | A new Image<TPixel>. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> LoadPixelData<TPixel>(ReadOnlySpan<TPixel> data, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<TPixel> | data | The readonly span of bytes containing image data. |
| int | width | The width of the final image. |
| int | height | The height of the final image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | A new Image<TPixel>. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | The data length is incorrect. |
Load<TPixel>(DecoderOptions, Stream)
Creates a new instance of the Image<TPixel> class from the given stream.
Declaration
public static Image<TPixel> Load<TPixel>(DecoderOptions options, Stream stream) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| Stream | stream | The stream containing image information. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> Load<TPixel>(DecoderOptions options, ReadOnlySpan<byte> data) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| ReadOnlySpan<byte> | data | The byte span containing encoded image data. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> Load<TPixel>(DecoderOptions options, string path) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| DecoderOptions | options | The general decoder options. |
| string | path | The file path to the image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> Load<TPixel>(Stream stream) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream containing image information. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> Load<TPixel>(ReadOnlySpan<byte> data) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| ReadOnlySpan<byte> | data | The byte span containing encoded image data. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> Load<TPixel>(string path) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The file path to the image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel format. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public void Save(Stream stream, IImageEncoder encoder)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to save the image to. |
| IImageEncoder | encoder | The encoder to save the image with. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public Task SaveAsync(Stream stream, IImageEncoder encoder, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The stream to save the image to. |
| IImageEncoder | encoder | The encoder to save the image with. |
| CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task | A Task representing the asynchronous operation. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if the stream or encoder is null. |
UpdateSize(Size)
Update the size of the image after mutation.
Declaration
protected void UpdateSize(Size size)
Parameters
| Type | Name | Description |
|---|---|---|
| Size | size | The Size. |
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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<byte> byteMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| IMemoryOwner<byte> | byteMemoryOwner | The IMemoryOwner<T> that is being transferred to the image. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<byte> byteMemoryOwner, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| IMemoryOwner<byte> | byteMemoryOwner | The IMemoryOwner<T> that is being transferred to the image |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
| ImageMetadata | metadata | The ImageMetadata |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<TPixel> pixelMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| IMemoryOwner<TPixel> | pixelMemoryOwner | The IMemoryOwner<T> that is being transferred to the image. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type. |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, IMemoryOwner<TPixel> pixelMemoryOwner, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| IMemoryOwner<TPixel> | pixelMemoryOwner | The IMemoryOwner<T> that is being transferred to the image |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
| ImageMetadata | metadata | The ImageMetadata |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<byte> byteMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| Memory<byte> | byteMemory | The byte memory representing the pixel data. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<byte> byteMemory, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| Memory<byte> | byteMemory | The byte memory representing the pixel data. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
| ImageMetadata | metadata | The ImageMetadata. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<TPixel> pixelMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| Memory<TPixel> | pixelMemory | The pixel memory. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, Memory<TPixel> pixelMemory, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| Memory<TPixel> | pixelMemory | The pixel memory. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
| ImageMetadata | metadata | The ImageMetadata. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, void* pointer, int bufferSizeInBytes, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| void* | pointer | The pointer to the target memory buffer to wrap. |
| int | bufferSizeInBytes | The byte length of the memory allocated. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Configuration configuration, void* pointer, int bufferSizeInBytes, int width, int height, ImageMetadata metadata) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Configuration | configuration | The Configuration |
| void* | pointer | The pointer to the target memory buffer to wrap. |
| int | bufferSizeInBytes | The byte length of the memory allocated. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
| ImageMetadata | metadata | The ImageMetadata. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type |
Exceptions
| Type | Condition |
|---|---|
| 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(IMemoryOwner<byte> byteMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| IMemoryOwner<byte> | byteMemoryOwner | The IMemoryOwner<T> that is being transferred to the image. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(IMemoryOwner<TPixel> pixelMemoryOwner, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| IMemoryOwner<TPixel> | pixelMemoryOwner | The IMemoryOwner<T> that is being transferred to the image. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Memory<byte> byteMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Memory<byte> | byteMemory | The byte memory representing the pixel data. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(Memory<TPixel> pixelMemory, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| Memory<TPixel> | pixelMemory | The pixel memory. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The 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.
Declaration
public static Image<TPixel> WrapMemory<TPixel>(void* pointer, int bufferSizeInBytes, int width, int height) where TPixel : unmanaged, IPixel<TPixel>
Parameters
| Type | Name | Description |
|---|---|---|
| void* | pointer | The pointer to the target memory buffer to wrap. |
| int | bufferSizeInBytes | The byte length of the memory allocated. |
| int | width | The width of the memory image. |
| int | height | The height of the memory image. |
Returns
| Type | Description |
|---|---|
| Image<TPixel> | An Image<TPixel> instance. |
Type Parameters
| Name | Description |
|---|---|
| TPixel | The pixel type. |