@ -16,22 +16,22 @@ public abstract partial class Image
/// Detects the encoded image format type from the specified file.
/// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="format">
/// <param name="format">
/// When this method returns, contains the format that matches the given file;
/// When this method returns, contains the format that matches the given file;
/// otherwise, the default value for the type of the <paramref name="format"/> parameter.
/// otherwise, the default value for the type of the <paramref name="format"/> parameter.
/// This parameter is passed uninitialized.
/// This parameter is passed uninitialized.
/// </param>
/// </param>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
public static bool TryDetectFormat ( string fileP ath, [ NotNullWhen ( true ) ] out IImageFormat ? format )
public static bool TryDetectFormat ( string p ath, [ NotNullWhen ( true ) ] out IImageFormat ? format )
= > TryDetectFormat ( DecoderOptions . Default , fileP ath, out format ) ;
= > TryDetectFormat ( DecoderOptions . Default , p ath, out format ) ;
/// <summary>
/// <summary>
/// Detects the encoded image format type from the specified file.
/// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="format">
/// <param name="format">
/// When this method returns, contains the format that matches the given file;
/// When this method returns, contains the format that matches the given file;
/// otherwise, the default value for the type of the <paramref name="format"/> parameter.
/// otherwise, the default value for the type of the <paramref name="format"/> parameter.
@ -39,11 +39,11 @@ public abstract partial class Image
/// </param>
/// </param>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
/// <returns><see langword="true"/> if a match is found; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The options are null.</exception>
public static bool TryDetectFormat ( DecoderOptions options , string fileP ath, [ NotNullWhen ( true ) ] out IImageFormat ? format )
public static bool TryDetectFormat ( DecoderOptions options , string p ath, [ NotNullWhen ( true ) ] out IImageFormat ? format )
{
{
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( options , nameof ( options ) ) ;
using Stream file = options . Configuration . FileSystem . OpenRead ( fileP ath) ;
using Stream file = options . Configuration . FileSystem . OpenRead ( p ath) ;
return TryDetectFormat ( options , file , out format ) ;
return TryDetectFormat ( options , file , out format ) ;
}
}
@ -51,31 +51,31 @@ public abstract partial class Image
/// Detects the encoded image format type from the specified file.
/// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns>
public static Task < Attempt < IImageFormat > > TryDetectFormatAsync (
public static Task < Attempt < IImageFormat > > TryDetectFormatAsync (
string fileP ath,
string p ath,
CancellationToken cancellationToken = default )
CancellationToken cancellationToken = default )
= > TryDetectFormatAsync ( DecoderOptions . Default , fileP ath, cancellationToken ) ;
= > TryDetectFormatAsync ( DecoderOptions . Default , p ath, cancellationToken ) ;
/// <summary>
/// <summary>
/// Detects the encoded image format type from the specified file.
/// Detects the encoded image format type from the specified file.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns>
/// <returns>A <see cref="Task{Attempt}"/> representing the asynchronous operation.</returns>
public static async Task < Attempt < IImageFormat > > TryDetectFormatAsync (
public static async Task < Attempt < IImageFormat > > TryDetectFormatAsync (
DecoderOptions options ,
DecoderOptions options ,
string fileP ath,
string p ath,
CancellationToken cancellationToken = default )
CancellationToken cancellationToken = default )
{
{
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( options , nameof ( options ) ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( fileP ath) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( p ath) ;
return await TryDetectFormatAsync ( options , stream , cancellationToken ) . ConfigureAwait ( false ) ;
return await TryDetectFormatAsync ( options , stream , cancellationToken ) . ConfigureAwait ( false ) ;
}
}
@ -83,22 +83,22 @@ public abstract partial class Image
/// Reads the raw image information from the specified file path without fully decoding it.
/// Reads the raw image information from the specified file path without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="info">
/// <param name="info">
/// When this method returns, contains the raw image information;
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// This parameter is passed uninitialized.
/// This parameter is passed uninitialized.
/// </param>
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
public static bool TryIdentify ( string fileP ath, [ NotNullWhen ( true ) ] out ImageInfo ? info )
public static bool TryIdentify ( string p ath, [ NotNullWhen ( true ) ] out ImageInfo ? info )
= > TryIdentify ( DecoderOptions . Default , fileP ath, out info ) ;
= > TryIdentify ( DecoderOptions . Default , p ath, out info ) ;
/// <summary>
/// <summary>
/// Reads the raw image information from the specified file path without fully decoding it.
/// Reads the raw image information from the specified file path without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="info">
/// <param name="info">
/// When this method returns, contains the raw image information;
/// When this method returns, contains the raw image information;
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
/// otherwise, the default value for the type of the <paramref name="info"/> parameter.
@ -106,11 +106,11 @@ public abstract partial class Image
/// </param>
/// </param>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <returns><see langword="true"/> if the information can be read; otherwise, <see langword="false"/></returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The options are null.</exception>
public static bool TryIdentify ( DecoderOptions options , string fileP ath, [ NotNullWhen ( true ) ] out ImageInfo ? info )
public static bool TryIdentify ( DecoderOptions options , string p ath, [ NotNullWhen ( true ) ] out ImageInfo ? info )
{
{
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( options , nameof ( options ) ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( fileP ath) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( p ath) ;
return TryIdentify ( options , stream , out info ) ;
return TryIdentify ( options , stream , out info ) ;
}
}
@ -118,197 +118,134 @@ public abstract partial class Image
/// Reads the raw image information from the specified stream without fully decoding it.
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>
/// <returns>
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// </returns>
/// </returns>
public static Task < Attempt < ImageInfo > > TryIdentifyAsync (
public static Task < Attempt < ImageInfo > > TryIdentifyAsync (
string fileP ath,
string p ath,
CancellationToken cancellationToken = default )
CancellationToken cancellationToken = default )
= > TryIdentifyAsync ( DecoderOptions . Default , fileP ath, cancellationToken ) ;
= > TryIdentifyAsync ( DecoderOptions . Default , p ath, cancellationToken ) ;
/// <summary>
/// <summary>
/// Reads the raw image information from the specified stream without fully decoding it.
/// Reads the raw image information from the specified stream without fully decoding it.
/// A return value indicates whether the operation succeeded.
/// A return value indicates whether the operation succeeded.
/// </summary>
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="fileP ath">The image file to open and to read the header from.</param>
/// <param name="p ath">The image file to open and to read the header from.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>
/// <returns>
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// The <see cref="Task{Attempt}"/> representing the asynchronous operation.
/// </returns>
/// </returns>
public static async Task < Attempt < ImageInfo > > TryIdentifyAsync (
public static async Task < Attempt < ImageInfo > > TryIdentifyAsync (
DecoderOptions options ,
DecoderOptions options ,
string fileP ath,
string p ath,
CancellationToken cancellationToken = default )
CancellationToken cancellationToken = default )
{
{
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( options , nameof ( options ) ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( fileP ath) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( p ath) ;
return await TryIdentifyAsync ( options , stream , cancellationToken ) . ConfigureAwait ( false ) ;
return await TryIdentifyAsync ( options , stream , cancellationToken ) . ConfigureAwait ( false ) ;
}
}
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// Creates a new instance of the <see cref="Image"/> class from the given file path.
/// The pixel format is automatically determined by the decoder.
/// </summary>
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <exception cref="NotSupportedException">
/// <returns><see cref="Image"/>.</returns>
/// Thrown if the stream is not readable nor seekable.
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// </exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <returns>The <see cref="Image"/>.</returns>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static Image Load ( string path )
public static Image Load ( string path )
= > Load ( DecoderOptions . Default , path ) ;
= > Load ( DecoderOptions . Default , path ) ;
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// Creates a new instance of the <see cref="Image"/> class from the given file path.
/// </summary>
/// The pixel format is automatically determined by the decoder.
/// <param name="path">The file path to the image.</param>
/// <param name="format">The mime type of the decoded image.</param>
/// <exception cref="NotSupportedException">
/// Thrown if the stream is not readable nor seekable.
/// </exception>
/// <returns>A new <see cref="Image{Rgba32}"/>.</returns>
public static Image Load ( string path , out IImageFormat format )
= > Load ( DecoderOptions . Default , path , out format ) ;
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <returns><see cref="Image"/>.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
/// <returns>The <see cref="Image"/>.</returns>
public static Image Load ( DecoderOptions options , string path )
public static Image Load ( DecoderOptions options , string path )
= > Load ( options , path , out _ ) ;
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
public static async Task < Image > LoadAsync (
DecoderOptions options ,
string path ,
CancellationToken cancellationToken = default )
{
{
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( path , nameof ( path ) ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( path ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( path ) ;
( Image img , _ ) = await LoadWithFormatAsync ( options , stream , cancellationToken )
return Load ( options , stream ) ;
. ConfigureAwait ( false ) ;
return img ;
}
}
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// Creates a new instance of the <see cref="Image"/> class from the given file path.
/// The pixel format is automatically determined by the decoder.
/// </summary>
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="ArgumentNullException">The decoder is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static Task < Image > LoadAsync ( string path , CancellationToken cancellationToken = default )
public static Task < Image > LoadAsync ( string path , CancellationToken cancellationToken = default )
= > LoadAsync ( DecoderOptions . Default , path , cancellationToken ) ;
= > LoadAsync ( DecoderOptions . Default , path , cancellationToken ) ;
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// Creates a new instance of the <see cref="Image"/> class from the given file path.
/// </summary>
/// The pixel format is automatically determined by the decoder.
/// <param name="path">The file path to the image.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
public static Task < Image < TPixel > > LoadAsync < TPixel > ( string path , CancellationToken cancellationToken = default )
where TPixel : unmanaged , IPixel < TPixel >
= > LoadAsync < TPixel > ( DecoderOptions . Default , path , cancellationToken ) ;
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// </summary>
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
public static async Task < Image < TPixel > > LoadAsync < TPixel > (
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
public static async Task < Image > LoadAsync (
DecoderOptions options ,
DecoderOptions options ,
string path ,
string path ,
CancellationToken cancellationToken = default )
CancellationToken cancellationToken = default )
where TPixel : unmanaged , IPixel < TPixel >
{
{
Guard . NotNull ( options , nameof ( options ) ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( path ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( path ) ;
( Image < TPixel > img , _ ) =
return await LoadAsync ( options , stream , cancellationToken ) . ConfigureAwait ( false ) ;
await LoadWithFormatAsync < TPixel > ( options , stream , cancellationToken ) . ConfigureAwait ( false ) ;
return img ;
}
}
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// Creates a new instance of the <see cref="Image{TPixel}"/> class from the given file path .
/// </summary>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <returns><see cref="Image{TPixel}"/>.</returns>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image < TPixel > Load < TPixel > ( string path )
public static Image < TPixel > Load < TPixel > ( string path )
where TPixel : unmanaged , IPixel < TPixel >
where TPixel : unmanaged , IPixel < TPixel >
= > Load < TPixel > ( DecoderOptions . Default , path ) ;
= > Load < TPixel > ( DecoderOptions . Default , path ) ;
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// Creates a new instance of the <see cref="Image{TPixel}"/> class from the given file path .
/// </summary>
/// </summary>
/// <param name="path">The file path to the image.</param>
/// <param name="format">The mime type of the decoded image.</param>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image < TPixel > Load < TPixel > ( string path , out IImageFormat format )
where TPixel : unmanaged , IPixel < TPixel >
= > Load < TPixel > ( DecoderOptions . Default , path , out format ) ;
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <returns><see cref="Image{TPixel}"/>.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image < TPixel > Load < TPixel > ( DecoderOptions options , string path )
public static Image < TPixel > Load < TPixel > ( DecoderOptions options , string path )
where TPixel : unmanaged , IPixel < TPixel >
where TPixel : unmanaged , IPixel < TPixel >
{
{
@ -320,47 +257,43 @@ public abstract partial class Image
}
}
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given file.
/// Creates a new instance of the <see cref="Image{TPixel}"/> class from the given file path .
/// </summary>
/// </summary>
/// <param name="options">The general decoder options.</ param>
/// <typeparam name="TPixel">The pixel format.</type param>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="format">The mime type of the decoded image .</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests .</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception >
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns >
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public static Task < Image < TPixel > > LoadAsync < TPixel > ( string path , CancellationToken cancellationToken = default )
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static Image < TPixel > Load < TPixel > ( DecoderOptions options , string path , out IImageFormat format )
where TPixel : unmanaged , IPixel < TPixel >
where TPixel : unmanaged , IPixel < TPixel >
{
= > LoadAsync < TPixel > ( DecoderOptions . Default , path , cancellationToken ) ;
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( path , nameof ( path ) ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( path ) ;
return Load < TPixel > ( options , stream , out format ) ;
}
/// <summary>
/// <summary>
/// Create a new instance of the <see cref="Image"/> class from the given file.
/// Creates a new instance of the <see cref="Image{TPixel}"/> class from the given file path.
/// The pixel type is selected by the decoder.
/// </summary>
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="options">The general decoder options.</param>
/// <param name="options">The general decoder options.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="path">The file path to the image.</param>
/// <param name="format">The mime type of the decoded image.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <exception cref="ArgumentNullException">The configuration is null.</exception>
/// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="ArgumentNullException">The path is null.</exception>
/// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
/// <exception cref="NotSupportedException">The file stream is not readable or the image format is not supported.</exception>
/// <exception cref="NotSupportedException">Image format is not supported.</exception>
/// <exception cref="InvalidImageContentException">The encoded image contains invalid content.</exception>
/// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
/// <exception cref="UnknownImageFormatException">The encoded image format is unknown.</exception>
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
public static async Task < Image < TPixel > > LoadAsync < TPixel > (
public static Image Load ( DecoderOptions options , string path , out IImageFormat format )
DecoderOptions options ,
string path ,
CancellationToken cancellationToken = default )
where TPixel : unmanaged , IPixel < TPixel >
{
{
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( options , nameof ( options ) ) ;
Guard . NotNull ( path , nameof ( path ) ) ;
Guard . NotNull ( path , nameof ( path ) ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( path ) ;
using Stream stream = options . Configuration . FileSystem . OpenRead ( path ) ;
return Load ( options , stream , out format ) ;
return await LoadAsync < TPixel > ( options , stream , cancellationToken ) . ConfigureAwait ( false ) ;
}
}
}
}