Browse Source

Changed optional arguments into overloads.

af/merge-core
Dirk Lemstra 9 years ago
committed by Dirk Lemstra
parent
commit
052ecdc337
  1. 18
      src/ImageSharp.Formats.Gif/ImageExtensions.cs
  2. 18
      src/ImageSharp.Formats.Jpeg/ImageExtensions.cs
  3. 18
      src/ImageSharp.Formats.Png/ImageExtensions.cs
  4. 132
      src/ImageSharp/Image.cs
  5. 215
      src/ImageSharp/Image/Image{TColor}.cs
  6. 2
      tests/ImageSharp.Tests/Image/ImageTests.cs

18
src/ImageSharp.Formats.Gif/ImageExtensions.cs

@ -15,6 +15,22 @@ namespace ImageSharp
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary>
/// Saves the image to the given stream with the gif format.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// </returns>
public static Image<TColor> SaveAsGif<TColor>(this Image<TColor> source, Stream stream)
where TColor : struct, IPixel<TColor>
{
return SaveAsGif(source, stream, null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream with the gif format. /// Saves the image to the given stream with the gif format.
/// </summary> /// </summary>
@ -26,7 +42,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TColor}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsGif<TColor>(this Image<TColor> source, Stream stream, IGifEncoderOptions options = null) public static Image<TColor> SaveAsGif<TColor>(this Image<TColor> source, Stream stream, IGifEncoderOptions options)
where TColor : struct, IPixel<TColor> where TColor : struct, IPixel<TColor>
{ {
GifEncoder encoder = new GifEncoder(); GifEncoder encoder = new GifEncoder();

18
src/ImageSharp.Formats.Jpeg/ImageExtensions.cs

@ -15,6 +15,22 @@ namespace ImageSharp
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary>
/// Saves the image to the given stream with the jpeg format.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// </returns>
public static Image<TColor> SaveAsJpeg<TColor>(this Image<TColor> source, Stream stream)
where TColor : struct, IPixel<TColor>
{
return SaveAsJpeg(source, stream, null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream with the jpeg format. /// Saves the image to the given stream with the jpeg format.
/// </summary> /// </summary>
@ -26,7 +42,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TColor}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsJpeg<TColor>(this Image<TColor> source, Stream stream, IJpegEncoderOptions options = null) public static Image<TColor> SaveAsJpeg<TColor>(this Image<TColor> source, Stream stream, IJpegEncoderOptions options)
where TColor : struct, IPixel<TColor> where TColor : struct, IPixel<TColor>
{ {
JpegEncoder encoder = new JpegEncoder(); JpegEncoder encoder = new JpegEncoder();

18
src/ImageSharp.Formats.Png/ImageExtensions.cs

@ -14,6 +14,22 @@ namespace ImageSharp
/// </summary> /// </summary>
public static partial class ImageExtensions public static partial class ImageExtensions
{ {
/// <summary>
/// Saves the image to the given stream with the png format.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// </returns>
public static Image<TColor> SaveAsPng<TColor>(this Image<TColor> source, Stream stream)
where TColor : struct, IPixel<TColor>
{
return SaveAsPng(source, stream, null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream with the png format. /// Saves the image to the given stream with the png format.
/// </summary> /// </summary>
@ -25,7 +41,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TColor}"/>.
/// </returns> /// </returns>
public static Image<TColor> SaveAsPng<TColor>(this Image<TColor> source, Stream stream, IPngEncoderOptions options = null) public static Image<TColor> SaveAsPng<TColor>(this Image<TColor> source, Stream stream, IPngEncoderOptions options)
where TColor : struct, IPixel<TColor> where TColor : struct, IPixel<TColor>
{ {
PngEncoder encoder = new PngEncoder(); PngEncoder encoder = new PngEncoder();

132
src/ImageSharp/Image.cs

@ -31,6 +31,48 @@ namespace ImageSharp
{ {
} }
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream)
: base(stream, null, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="options">
/// The options for the decoder.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream, IDecoderOptions options)
: base(stream, options, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream, Configuration configuration)
: base(stream, null, configuration)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image"/> class. /// Initializes a new instance of the <see cref="Image"/> class.
/// </summary> /// </summary>
@ -44,12 +86,54 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream, IDecoderOptions options = null, Configuration configuration = null) public Image(Stream stream, IDecoderOptions options, Configuration configuration)
: base(stream, options, configuration) : base(stream, options, configuration)
{ {
} }
#if !NETSTANDARD1_1 #if !NETSTANDARD1_1
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="filePath">
/// A file path to read image information.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath)
: base(filePath, null, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="filePath">
/// A file path to read image information.
/// </param>
/// <param name="options">
/// The options for the decoder.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath, IDecoderOptions options)
: base(filePath, options, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="filePath">
/// A file path to read image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath, Configuration configuration)
: base(filePath, null, configuration)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image"/> class. /// Initializes a new instance of the <see cref="Image"/> class.
/// </summary> /// </summary>
@ -63,12 +147,54 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath, IDecoderOptions options = null, Configuration configuration = null) public Image(string filePath, IDecoderOptions options, Configuration configuration)
: base(filePath, options, configuration) : base(filePath, options, configuration)
{ {
} }
#endif #endif
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes)
: base(bytes, null, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="options">
/// The options for the decoder.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes, IDecoderOptions options)
: base(bytes, options, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image"/> class.
/// </summary>
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes, Configuration configuration)
: base(bytes, null, configuration)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image"/> class. /// Initializes a new instance of the <see cref="Image"/> class.
/// </summary> /// </summary>
@ -82,7 +208,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes, IDecoderOptions options = null, Configuration configuration = null) public Image(byte[] bytes, IDecoderOptions options, Configuration configuration)
: base(bytes, options, configuration) : base(bytes, options, configuration)
{ {
} }

215
src/ImageSharp/Image/Image{TColor}.cs

@ -46,6 +46,48 @@ namespace ImageSharp
this.CurrentImageFormat = this.Configuration.ImageFormats.First(); this.CurrentImageFormat = this.Configuration.ImageFormats.First();
} }
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream)
: this(stream, null, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="options">
/// The options for the decoder.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream, IDecoderOptions options)
: this(stream, options, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="stream">
/// The stream containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream, Configuration configuration)
: this(stream, null, configuration)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class. /// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary> /// </summary>
@ -59,7 +101,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="stream"/> is null.</exception>
public Image(Stream stream, IDecoderOptions options = null, Configuration configuration = null) public Image(Stream stream, IDecoderOptions options, Configuration configuration)
: base(configuration) : base(configuration)
{ {
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
@ -67,6 +109,48 @@ namespace ImageSharp
} }
#if !NETSTANDARD1_1 #if !NETSTANDARD1_1
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="filePath">
/// The file containing image information.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath)
: this(filePath, null, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="filePath">
/// The file containing image information.
/// </param>
/// <param name="options">
/// The options for the decoder.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath, IDecoderOptions options)
: this(filePath, options, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="filePath">
/// The file containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath, Configuration configuration)
: this(filePath, null, configuration)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class. /// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary> /// </summary>
@ -80,7 +164,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="filePath"/> is null.</exception>
public Image(string filePath, IDecoderOptions options = null, Configuration configuration = null) public Image(string filePath, IDecoderOptions options, Configuration configuration)
: base(configuration) : base(configuration)
{ {
Guard.NotNull(filePath, nameof(filePath)); Guard.NotNull(filePath, nameof(filePath));
@ -91,6 +175,48 @@ namespace ImageSharp
} }
#endif #endif
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes)
: this(bytes, null, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="options">
/// The options for the decoder.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes, IDecoderOptions options)
: this(bytes, options, null)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary>
/// <param name="bytes">
/// The byte array containing image information.
/// </param>
/// <param name="configuration">
/// The configuration providing initialization code which allows extending the library.
/// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes, Configuration configuration)
: this(bytes, null, configuration)
{
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TColor}"/> class. /// Initializes a new instance of the <see cref="Image{TColor}"/> class.
/// </summary> /// </summary>
@ -104,7 +230,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library. /// The configuration providing initialization code which allows extending the library.
/// </param> /// </param>
/// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="bytes"/> is null.</exception>
public Image(byte[] bytes, IDecoderOptions options = null, Configuration configuration = null) public Image(byte[] bytes, IDecoderOptions options, Configuration configuration)
: base(configuration) : base(configuration)
{ {
Guard.NotNull(bytes, nameof(bytes)); Guard.NotNull(bytes, nameof(bytes));
@ -202,6 +328,17 @@ namespace ImageSharp
} }
} }
/// <summary>
/// Saves the image to the given stream using the currently loaded image format.
/// </summary>
/// <param name="stream">The stream to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream)
{
return this.Save(stream, (IEncoderOptions)null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream using the currently loaded image format. /// Saves the image to the given stream using the currently loaded image format.
/// </summary> /// </summary>
@ -209,13 +346,24 @@ namespace ImageSharp
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream, IEncoderOptions options = null) public Image<TColor> Save(Stream stream, IEncoderOptions options)
{ {
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
this.CurrentImageFormat.Encoder.Encode(this, stream, options); this.CurrentImageFormat.Encoder.Encode(this, stream, options);
return this; return this;
} }
/// <summary>
/// Saves the image to the given stream using the given image format.
/// </summary>
/// <param name="stream">The stream to save the image to.</param>
/// <param name="format">The format to save the image as.</param>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream, IImageFormat format)
{
return this.Save(stream, format, null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream using the given image format. /// Saves the image to the given stream using the given image format.
/// </summary> /// </summary>
@ -223,7 +371,7 @@ namespace ImageSharp
/// <param name="format">The format to save the image as.</param> /// <param name="format">The format to save the image as.</param>
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(Stream stream, IImageFormat format, IEncoderOptions options = null) public Image<TColor> Save(Stream stream, IImageFormat format, IEncoderOptions options)
{ {
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
Guard.NotNull(format, nameof(format)); Guard.NotNull(format, nameof(format));
@ -231,6 +379,20 @@ namespace ImageSharp
return this; return this;
} }
/// <summary>
/// Saves the image to the given stream using the given image encoder.
/// </summary>
/// <param name="stream">The stream to save the image to.</param>
/// <param name="encoder">The encoder to save the image with.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream or encoder is null.</exception>
/// <returns>
/// The <see cref="Image{TColor}"/>.
/// </returns>
public Image<TColor> Save(Stream stream, IImageEncoder encoder)
{
return this.Save(stream, encoder, null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream using the given image encoder. /// Saves the image to the given stream using the given image encoder.
/// </summary> /// </summary>
@ -241,7 +403,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The <see cref="Image{TColor}"/>. /// The <see cref="Image{TColor}"/>.
/// </returns> /// </returns>
public Image<TColor> Save(Stream stream, IImageEncoder encoder, IEncoderOptions options = null) public Image<TColor> Save(Stream stream, IImageEncoder encoder, IEncoderOptions options)
{ {
Guard.NotNull(stream, nameof(stream)); Guard.NotNull(stream, nameof(stream));
Guard.NotNull(encoder, nameof(encoder)); Guard.NotNull(encoder, nameof(encoder));
@ -257,6 +419,17 @@ namespace ImageSharp
} }
#if !NETSTANDARD1_1 #if !NETSTANDARD1_1
/// <summary>
/// Saves the image to the given stream using the currently loaded image format.
/// </summary>
/// <param name="filePath">The file path to save the image to.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath)
{
return this.Save(filePath, (IEncoderOptions)null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream using the currently loaded image format. /// Saves the image to the given stream using the currently loaded image format.
/// </summary> /// </summary>
@ -264,7 +437,7 @@ namespace ImageSharp
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the stream is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IEncoderOptions options = null) public Image<TColor> Save(string filePath, IEncoderOptions options)
{ {
string ext = Path.GetExtension(filePath).Trim('.'); string ext = Path.GetExtension(filePath).Trim('.');
IImageFormat format = this.Configuration.ImageFormats.SingleOrDefault(f => f.SupportedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase)); IImageFormat format = this.Configuration.ImageFormats.SingleOrDefault(f => f.SupportedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase));
@ -276,6 +449,18 @@ namespace ImageSharp
return this.Save(filePath, format); return this.Save(filePath, format);
} }
/// <summary>
/// Saves the image to the given stream using the currently loaded image format.
/// </summary>
/// <param name="filePath">The file path to save the image to.</param>
/// <param name="format">The format to save the image as.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageFormat format)
{
return this.Save(filePath, format, null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream using the currently loaded image format. /// Saves the image to the given stream using the currently loaded image format.
/// </summary> /// </summary>
@ -284,7 +469,7 @@ namespace ImageSharp
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the format is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageFormat format, IEncoderOptions options = null) public Image<TColor> Save(string filePath, IImageFormat format, IEncoderOptions options)
{ {
Guard.NotNull(format, nameof(format)); Guard.NotNull(format, nameof(format));
using (FileStream fs = File.Create(filePath)) using (FileStream fs = File.Create(filePath))
@ -293,6 +478,18 @@ namespace ImageSharp
} }
} }
/// <summary>
/// Saves the image to the given stream using the currently loaded image format.
/// </summary>
/// <param name="filePath">The file path to save the image to.</param>
/// <param name="encoder">The encoder to save the image with.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageEncoder encoder)
{
return this.Save(filePath, encoder, null);
}
/// <summary> /// <summary>
/// Saves the image to the given stream using the currently loaded image format. /// Saves the image to the given stream using the currently loaded image format.
/// </summary> /// </summary>
@ -301,7 +498,7 @@ namespace ImageSharp
/// <param name="options">The options for the encoder.</param> /// <param name="options">The options for the encoder.</param>
/// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception> /// <exception cref="System.ArgumentNullException">Thrown if the encoder is null.</exception>
/// <returns>The <see cref="Image{TColor}"/></returns> /// <returns>The <see cref="Image{TColor}"/></returns>
public Image<TColor> Save(string filePath, IImageEncoder encoder, IEncoderOptions options = null) public Image<TColor> Save(string filePath, IImageEncoder encoder, IEncoderOptions options)
{ {
Guard.NotNull(encoder, nameof(encoder)); Guard.NotNull(encoder, nameof(encoder));
using (FileStream fs = File.Create(filePath)) using (FileStream fs = File.Create(filePath))

2
tests/ImageSharp.Tests/Image/ImageTests.cs

@ -59,7 +59,7 @@ namespace ImageSharp.Tests
ArgumentNullException ex = Assert.Throws<ArgumentNullException>( ArgumentNullException ex = Assert.Throws<ArgumentNullException>(
() => () =>
{ {
new Image(null); new Image((string) null);
}); });
} }

Loading…
Cancel
Save