diff --git a/src/ImageSharp.Formats.Gif/ImageExtensions.cs b/src/ImageSharp.Formats.Gif/ImageExtensions.cs
index dcf4ab29a5..1ba03ed351 100644
--- a/src/ImageSharp.Formats.Gif/ImageExtensions.cs
+++ b/src/ImageSharp.Formats.Gif/ImageExtensions.cs
@@ -15,6 +15,22 @@ namespace ImageSharp
///
public static partial class ImageExtensions
{
+ ///
+ /// Saves the image to the given stream with the gif format.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The stream to save the image to.
+ /// Thrown if the stream is null.
+ ///
+ /// The .
+ ///
+ public static Image SaveAsGif(this Image source, Stream stream)
+ where TColor : struct, IPixel
+ {
+ return SaveAsGif(source, stream, null);
+ }
+
///
/// Saves the image to the given stream with the gif format.
///
@@ -26,7 +42,7 @@ namespace ImageSharp
///
/// The .
///
- public static Image SaveAsGif(this Image source, Stream stream, IGifEncoderOptions options = null)
+ public static Image SaveAsGif(this Image source, Stream stream, IGifEncoderOptions options)
where TColor : struct, IPixel
{
GifEncoder encoder = new GifEncoder();
diff --git a/src/ImageSharp.Formats.Jpeg/ImageExtensions.cs b/src/ImageSharp.Formats.Jpeg/ImageExtensions.cs
index 311bcc6435..351275ebb7 100644
--- a/src/ImageSharp.Formats.Jpeg/ImageExtensions.cs
+++ b/src/ImageSharp.Formats.Jpeg/ImageExtensions.cs
@@ -15,6 +15,22 @@ namespace ImageSharp
///
public static partial class ImageExtensions
{
+ ///
+ /// Saves the image to the given stream with the jpeg format.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The stream to save the image to.
+ /// Thrown if the stream is null.
+ ///
+ /// The .
+ ///
+ public static Image SaveAsJpeg(this Image source, Stream stream)
+ where TColor : struct, IPixel
+ {
+ return SaveAsJpeg(source, stream, null);
+ }
+
///
/// Saves the image to the given stream with the jpeg format.
///
@@ -26,7 +42,7 @@ namespace ImageSharp
///
/// The .
///
- public static Image SaveAsJpeg(this Image source, Stream stream, IJpegEncoderOptions options = null)
+ public static Image SaveAsJpeg(this Image source, Stream stream, IJpegEncoderOptions options)
where TColor : struct, IPixel
{
JpegEncoder encoder = new JpegEncoder();
diff --git a/src/ImageSharp.Formats.Png/ImageExtensions.cs b/src/ImageSharp.Formats.Png/ImageExtensions.cs
index f08ab8ee71..79e96175c1 100644
--- a/src/ImageSharp.Formats.Png/ImageExtensions.cs
+++ b/src/ImageSharp.Formats.Png/ImageExtensions.cs
@@ -14,6 +14,22 @@ namespace ImageSharp
///
public static partial class ImageExtensions
{
+ ///
+ /// Saves the image to the given stream with the png format.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The stream to save the image to.
+ /// Thrown if the stream is null.
+ ///
+ /// The .
+ ///
+ public static Image SaveAsPng(this Image source, Stream stream)
+ where TColor : struct, IPixel
+ {
+ return SaveAsPng(source, stream, null);
+ }
+
///
/// Saves the image to the given stream with the png format.
///
@@ -25,7 +41,7 @@ namespace ImageSharp
///
/// The .
///
- public static Image SaveAsPng(this Image source, Stream stream, IPngEncoderOptions options = null)
+ public static Image SaveAsPng(this Image source, Stream stream, IPngEncoderOptions options)
where TColor : struct, IPixel
{
PngEncoder encoder = new PngEncoder();
diff --git a/src/ImageSharp/Image.cs b/src/ImageSharp/Image.cs
index b1c1252ab4..af31eff792 100644
--- a/src/ImageSharp/Image.cs
+++ b/src/ImageSharp/Image.cs
@@ -31,6 +31,48 @@ namespace ImageSharp
{
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The stream containing image information.
+ ///
+ /// Thrown if the is null.
+ public Image(Stream stream)
+ : base(stream, null, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The stream containing image information.
+ ///
+ ///
+ /// The options for the decoder.
+ ///
+ /// Thrown if the is null.
+ public Image(Stream stream, IDecoderOptions options)
+ : base(stream, options, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The stream containing image information.
+ ///
+ ///
+ /// The configuration providing initialization code which allows extending the library.
+ ///
+ /// Thrown if the is null.
+ public Image(Stream stream, Configuration configuration)
+ : base(stream, null, configuration)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -44,12 +86,54 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library.
///
/// Thrown if the is null.
- public Image(Stream stream, IDecoderOptions options = null, Configuration configuration = null)
+ public Image(Stream stream, IDecoderOptions options, Configuration configuration)
: base(stream, options, configuration)
{
}
#if !NETSTANDARD1_1
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// A file path to read image information.
+ ///
+ /// Thrown if the is null.
+ public Image(string filePath)
+ : base(filePath, null, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// A file path to read image information.
+ ///
+ ///
+ /// The options for the decoder.
+ ///
+ /// Thrown if the is null.
+ public Image(string filePath, IDecoderOptions options)
+ : base(filePath, options, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// A file path to read image information.
+ ///
+ ///
+ /// The configuration providing initialization code which allows extending the library.
+ ///
+ /// Thrown if the is null.
+ public Image(string filePath, Configuration configuration)
+ : base(filePath, null, configuration)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -63,12 +147,54 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library.
///
/// Thrown if the is null.
- public Image(string filePath, IDecoderOptions options = null, Configuration configuration = null)
+ public Image(string filePath, IDecoderOptions options, Configuration configuration)
: base(filePath, options, configuration)
{
}
#endif
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes)
+ : base(bytes, null, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ ///
+ /// The options for the decoder.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes, IDecoderOptions options)
+ : base(bytes, options, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ ///
+ /// The configuration providing initialization code which allows extending the library.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes, Configuration configuration)
+ : base(bytes, null, configuration)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -82,7 +208,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library.
///
/// Thrown if the is null.
- public Image(byte[] bytes, IDecoderOptions options = null, Configuration configuration = null)
+ public Image(byte[] bytes, IDecoderOptions options, Configuration configuration)
: base(bytes, options, configuration)
{
}
diff --git a/src/ImageSharp/Image/Image{TColor}.cs b/src/ImageSharp/Image/Image{TColor}.cs
index 69b99ce13a..27dee54342 100644
--- a/src/ImageSharp/Image/Image{TColor}.cs
+++ b/src/ImageSharp/Image/Image{TColor}.cs
@@ -46,6 +46,48 @@ namespace ImageSharp
this.CurrentImageFormat = this.Configuration.ImageFormats.First();
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The stream containing image information.
+ ///
+ /// Thrown if the is null.
+ public Image(Stream stream)
+ : this(stream, null, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The stream containing image information.
+ ///
+ ///
+ /// The options for the decoder.
+ ///
+ /// Thrown if the is null.
+ public Image(Stream stream, IDecoderOptions options)
+ : this(stream, options, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The stream containing image information.
+ ///
+ ///
+ /// The configuration providing initialization code which allows extending the library.
+ ///
+ /// Thrown if the is null.
+ public Image(Stream stream, Configuration configuration)
+ : this(stream, null, configuration)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -59,7 +101,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library.
///
/// Thrown if the is null.
- public Image(Stream stream, IDecoderOptions options = null, Configuration configuration = null)
+ public Image(Stream stream, IDecoderOptions options, Configuration configuration)
: base(configuration)
{
Guard.NotNull(stream, nameof(stream));
@@ -67,6 +109,48 @@ namespace ImageSharp
}
#if !NETSTANDARD1_1
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The file containing image information.
+ ///
+ /// Thrown if the is null.
+ public Image(string filePath)
+ : this(filePath, null, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The file containing image information.
+ ///
+ ///
+ /// The options for the decoder.
+ ///
+ /// Thrown if the is null.
+ public Image(string filePath, IDecoderOptions options)
+ : this(filePath, options, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The file containing image information.
+ ///
+ ///
+ /// The configuration providing initialization code which allows extending the library.
+ ///
+ /// Thrown if the is null.
+ public Image(string filePath, Configuration configuration)
+ : this(filePath, null, configuration)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -80,7 +164,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library.
///
/// Thrown if the is null.
- public Image(string filePath, IDecoderOptions options = null, Configuration configuration = null)
+ public Image(string filePath, IDecoderOptions options, Configuration configuration)
: base(configuration)
{
Guard.NotNull(filePath, nameof(filePath));
@@ -91,6 +175,48 @@ namespace ImageSharp
}
#endif
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes)
+ : this(bytes, null, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ ///
+ /// The options for the decoder.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes, IDecoderOptions options)
+ : this(bytes, options, null)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The byte array containing image information.
+ ///
+ ///
+ /// The configuration providing initialization code which allows extending the library.
+ ///
+ /// Thrown if the is null.
+ public Image(byte[] bytes, Configuration configuration)
+ : this(bytes, null, configuration)
+ {
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -104,7 +230,7 @@ namespace ImageSharp
/// The configuration providing initialization code which allows extending the library.
///
/// Thrown if the is null.
- public Image(byte[] bytes, IDecoderOptions options = null, Configuration configuration = null)
+ public Image(byte[] bytes, IDecoderOptions options, Configuration configuration)
: base(configuration)
{
Guard.NotNull(bytes, nameof(bytes));
@@ -202,6 +328,17 @@ namespace ImageSharp
}
}
+ ///
+ /// Saves the image to the given stream using the currently loaded image format.
+ ///
+ /// The stream to save the image to.
+ /// Thrown if the stream is null.
+ /// The
+ public Image Save(Stream stream)
+ {
+ return this.Save(stream, (IEncoderOptions)null);
+ }
+
///
/// Saves the image to the given stream using the currently loaded image format.
///
@@ -209,13 +346,24 @@ namespace ImageSharp
/// The options for the encoder.
/// Thrown if the stream is null.
/// The
- public Image Save(Stream stream, IEncoderOptions options = null)
+ public Image Save(Stream stream, IEncoderOptions options)
{
Guard.NotNull(stream, nameof(stream));
this.CurrentImageFormat.Encoder.Encode(this, stream, options);
return this;
}
+ ///
+ /// Saves the image to the given stream using the given image format.
+ ///
+ /// The stream to save the image to.
+ /// The format to save the image as.
+ /// The
+ public Image Save(Stream stream, IImageFormat format)
+ {
+ return this.Save(stream, format, null);
+ }
+
///
/// Saves the image to the given stream using the given image format.
///
@@ -223,7 +371,7 @@ namespace ImageSharp
/// The format to save the image as.
/// The options for the encoder.
/// The
- public Image Save(Stream stream, IImageFormat format, IEncoderOptions options = null)
+ public Image Save(Stream stream, IImageFormat format, IEncoderOptions options)
{
Guard.NotNull(stream, nameof(stream));
Guard.NotNull(format, nameof(format));
@@ -231,6 +379,20 @@ namespace ImageSharp
return this;
}
+ ///
+ /// Saves the image to the given stream using the given image encoder.
+ ///
+ /// The stream to save the image to.
+ /// The encoder to save the image with.
+ /// Thrown if the stream or encoder is null.
+ ///
+ /// The .
+ ///
+ public Image Save(Stream stream, IImageEncoder encoder)
+ {
+ return this.Save(stream, encoder, null);
+ }
+
///
/// Saves the image to the given stream using the given image encoder.
///
@@ -241,7 +403,7 @@ namespace ImageSharp
///
/// The .
///
- public Image Save(Stream stream, IImageEncoder encoder, IEncoderOptions options = null)
+ public Image Save(Stream stream, IImageEncoder encoder, IEncoderOptions options)
{
Guard.NotNull(stream, nameof(stream));
Guard.NotNull(encoder, nameof(encoder));
@@ -257,6 +419,17 @@ namespace ImageSharp
}
#if !NETSTANDARD1_1
+ ///
+ /// Saves the image to the given stream using the currently loaded image format.
+ ///
+ /// The file path to save the image to.
+ /// Thrown if the stream is null.
+ /// The
+ public Image Save(string filePath)
+ {
+ return this.Save(filePath, (IEncoderOptions)null);
+ }
+
///
/// Saves the image to the given stream using the currently loaded image format.
///
@@ -264,7 +437,7 @@ namespace ImageSharp
/// The options for the encoder.
/// Thrown if the stream is null.
/// The
- public Image Save(string filePath, IEncoderOptions options = null)
+ public Image Save(string filePath, IEncoderOptions options)
{
string ext = Path.GetExtension(filePath).Trim('.');
IImageFormat format = this.Configuration.ImageFormats.SingleOrDefault(f => f.SupportedExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase));
@@ -276,6 +449,18 @@ namespace ImageSharp
return this.Save(filePath, format);
}
+ ///
+ /// Saves the image to the given stream using the currently loaded image format.
+ ///
+ /// The file path to save the image to.
+ /// The format to save the image as.
+ /// Thrown if the format is null.
+ /// The
+ public Image Save(string filePath, IImageFormat format)
+ {
+ return this.Save(filePath, format, null);
+ }
+
///
/// Saves the image to the given stream using the currently loaded image format.
///
@@ -284,7 +469,7 @@ namespace ImageSharp
/// The options for the encoder.
/// Thrown if the format is null.
/// The
- public Image Save(string filePath, IImageFormat format, IEncoderOptions options = null)
+ public Image Save(string filePath, IImageFormat format, IEncoderOptions options)
{
Guard.NotNull(format, nameof(format));
using (FileStream fs = File.Create(filePath))
@@ -293,6 +478,18 @@ namespace ImageSharp
}
}
+ ///
+ /// Saves the image to the given stream using the currently loaded image format.
+ ///
+ /// The file path to save the image to.
+ /// The encoder to save the image with.
+ /// Thrown if the encoder is null.
+ /// The
+ public Image Save(string filePath, IImageEncoder encoder)
+ {
+ return this.Save(filePath, encoder, null);
+ }
+
///
/// Saves the image to the given stream using the currently loaded image format.
///
@@ -301,7 +498,7 @@ namespace ImageSharp
/// The options for the encoder.
/// Thrown if the encoder is null.
/// The
- public Image Save(string filePath, IImageEncoder encoder, IEncoderOptions options = null)
+ public Image Save(string filePath, IImageEncoder encoder, IEncoderOptions options)
{
Guard.NotNull(encoder, nameof(encoder));
using (FileStream fs = File.Create(filePath))
diff --git a/tests/ImageSharp.Tests/Image/ImageTests.cs b/tests/ImageSharp.Tests/Image/ImageTests.cs
index aea4330c68..0ed724fadc 100644
--- a/tests/ImageSharp.Tests/Image/ImageTests.cs
+++ b/tests/ImageSharp.Tests/Image/ImageTests.cs
@@ -59,7 +59,7 @@ namespace ImageSharp.Tests
ArgumentNullException ex = Assert.Throws(
() =>
{
- new Image(null);
+ new Image((string) null);
});
}