33
44using System ;
55using System . IO ;
6+ using System . Threading . Tasks ;
67using SixLabors . ImageSharp . Formats ;
78using SixLabors . ImageSharp . PixelFormats ;
89
@@ -89,6 +90,17 @@ public static IImageInfo Identify(Configuration configuration, string filePath,
8990 public static Image Load ( string path )
9091 => Load ( Configuration . Default , path ) ;
9192
93+ /// <summary>
94+ /// Create a new instance of the <see cref="Image"/> class from the given file.
95+ /// </summary>
96+ /// <param name="path">The file path to the image.</param>
97+ /// <exception cref="NotSupportedException">
98+ /// Thrown if the stream is not readable nor seekable.
99+ /// </exception>
100+ /// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
101+ public static Task < Image > LoadAsync ( string path )
102+ => LoadAsync ( Configuration . Default , path ) ;
103+
92104 /// <summary>
93105 /// Create a new instance of the <see cref="Image"/> class from the given file.
94106 /// </summary>
@@ -114,6 +126,25 @@ public static Image Load(string path, out IImageFormat format)
114126 public static Image Load ( Configuration configuration , string path )
115127 => Load ( configuration , path , out _ ) ;
116128
129+ /// <summary>
130+ /// Create a new instance of the <see cref="Image"/> class from the given file.
131+ /// </summary>
132+ /// <param name="configuration">The configuration for the decoder.</param>
133+ /// <param name="path">The file path to the image.</param>
134+ /// <exception cref="ArgumentNullException">The configuration is null.</exception>
135+ /// <exception cref="ArgumentNullException">The path is null.</exception>
136+ /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
137+ /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
138+ /// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
139+ public static async Task < Image > LoadAsync ( Configuration configuration , string path )
140+ {
141+ using ( Stream stream = configuration . FileSystem . OpenRead ( path ) )
142+ {
143+ ( Image img , _ ) = await LoadWithFormatAsync ( configuration , stream ) . ConfigureAwait ( false ) ;
144+ return img ;
145+ }
146+ }
147+
117148 /// <summary>
118149 /// Create a new instance of the <see cref="Image"/> class from the given file.
119150 /// </summary>
@@ -137,6 +168,29 @@ public static Image Load(Configuration configuration, string path, IImageDecoder
137168 }
138169 }
139170
171+ /// <summary>
172+ /// Create a new instance of the <see cref="Image"/> class from the given file.
173+ /// </summary>
174+ /// <param name="configuration">The Configuration.</param>
175+ /// <param name="path">The file path to the image.</param>
176+ /// <param name="decoder">The decoder.</param>
177+ /// <exception cref="ArgumentNullException">The configuration is null.</exception>
178+ /// <exception cref="ArgumentNullException">The path is null.</exception>
179+ /// <exception cref="ArgumentNullException">The decoder is null.</exception>
180+ /// <exception cref="UnknownImageFormatException">Image format not recognised.</exception>
181+ /// <exception cref="InvalidImageContentException">Image contains invalid content.</exception>
182+ /// <returns>A <see cref="Task{Image}"/> representing the asynchronous operation.</returns>
183+ public static Task < Image > LoadAsync ( Configuration configuration , string path , IImageDecoder decoder )
184+ {
185+ Guard . NotNull ( configuration , nameof ( configuration ) ) ;
186+ Guard . NotNull ( path , nameof ( path ) ) ;
187+
188+ using ( Stream stream = configuration . FileSystem . OpenRead ( path ) )
189+ {
190+ return LoadAsync ( configuration , stream , decoder ) ;
191+ }
192+ }
193+
140194 /// <summary>
141195 /// Create a new instance of the <see cref="Image"/> class from the given file.
142196 /// </summary>
0 commit comments