diff --git a/src/ImageProcessorCore/Image.cs b/src/ImageProcessorCore/Image.cs
index 1bcdbb2c3a..fce2543a87 100644
--- a/src/ImageProcessorCore/Image.cs
+++ b/src/ImageProcessorCore/Image.cs
@@ -7,7 +7,6 @@ namespace ImageProcessorCore
{
using System;
using System.Collections.Generic;
- using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -77,27 +76,9 @@ namespace ImageProcessorCore
this.RepeatCount = other.RepeatCount;
this.HorizontalResolution = other.HorizontalResolution;
this.VerticalResolution = other.VerticalResolution;
- this.Formats = other.Formats;
this.CurrentImageFormat = other.CurrentImageFormat;
}
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The other to create this instance from.
- ///
- ///
- /// Thrown if the given is null.
- ///
- public Image(ImageFrame other)
- : base(other)
- {
- // Most likely a gif
- // TODO: Should this be aproperty on ImageFrame?
- this.CurrentImageFormat = Bootstrapper.Instance.ImageFormats.First(f => f.GetType() == typeof(GifFormat));
- }
-
///
/// Initializes a new instance of the class.
///
@@ -108,29 +89,13 @@ namespace ImageProcessorCore
public Image(Stream stream)
{
Guard.NotNull(stream, nameof(stream));
- this.Load(stream, Bootstrapper.Instance.ImageFormats.ToList());
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The stream containing image information.
- ///
- ///
- /// The collection of .
- ///
- /// Thrown if the stream is null.
- public Image(Stream stream, params IImageFormat[] formats)
- {
- Guard.NotNull(stream, nameof(stream));
- this.Load(stream, formats.ToList());
+ this.Load(stream);
}
///
/// Gets a list of supported image formats.
///
- public IReadOnlyCollection Formats { get; internal set; } = Bootstrapper.Instance.ImageFormats;
+ public IReadOnlyCollection Formats { get; } = Bootstrapper.Instance.ImageFormats;
///
public double HorizontalResolution { get; set; } = DefaultHorizontalResolution;
@@ -246,15 +211,12 @@ namespace ImageProcessorCore
/// Loads the image from the given stream.
///
/// The stream containing image information.
- /// The collection of .
///
/// Thrown if the stream is not readable nor seekable.
///
- private void Load(Stream stream, IList formats)
+ private void Load(Stream stream)
{
- if (!formats.Any()) { return; }
-
- this.Formats = new ReadOnlyCollection(formats);
+ if (!this.Formats.Any()) { return; }
if (!stream.CanRead)
{
@@ -266,7 +228,7 @@ namespace ImageProcessorCore
throw new NotSupportedException("The stream does not support seeking.");
}
- int maxHeaderSize = formats.Max(x => x.Decoder.HeaderSize);
+ int maxHeaderSize = this.Formats.Max(x => x.Decoder.HeaderSize);
if (maxHeaderSize > 0)
{
byte[] header = new byte[maxHeaderSize];
@@ -275,7 +237,7 @@ namespace ImageProcessorCore
stream.Read(header, 0, maxHeaderSize);
stream.Position = 0;
- IImageFormat format = formats.FirstOrDefault(x => x.Decoder.IsSupportedFileFormat(header));
+ IImageFormat format = this.Formats.FirstOrDefault(x => x.Decoder.IsSupportedFileFormat(header));
if (format != null)
{
format.Decoder.Decode(this, stream);
@@ -287,7 +249,7 @@ namespace ImageProcessorCore
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Image cannot be loaded. Available formats:");
- foreach (IImageFormat format in formats)
+ foreach (IImageFormat format in this.Formats)
{
stringBuilder.AppendLine("-" + format);
}
diff --git a/src/ImageProcessorCore/ImageExtensions.cs b/src/ImageProcessorCore/ImageExtensions.cs
index 67a6f9c61f..f34bab750b 100644
--- a/src/ImageProcessorCore/ImageExtensions.cs
+++ b/src/ImageProcessorCore/ImageExtensions.cs
@@ -127,6 +127,7 @@ namespace ImageProcessorCore
/// Whether to clone the image.
/// The to perform against the image.
/// The .
+ /// Thrown if the has been disposed.
private static Image PerformAction(Image source, bool clone, Action action)
{
if (source.IsDisposed)
@@ -142,7 +143,6 @@ namespace ImageProcessorCore
// TODO: Check why we need to set these?
HorizontalResolution = source.HorizontalResolution,
VerticalResolution = source.VerticalResolution,
- Formats = source.Formats,
CurrentImageFormat = source.CurrentImageFormat,
RepeatCount = source.RepeatCount
};
@@ -165,9 +165,9 @@ namespace ImageProcessorCore
}
}
- // According to http://stackoverflow.com/questions/37921815/idisposable-unmanaged-fields-reference-types-and-assignments/37922955#37922955
+ // According to http://stackoverflow.com/questions/37921815/idisposable-unmanaged-fields-reference-types-and-assignments
// There's no need to dispose of the original image as the GC will get around to cleaning it up now there are no references to the original data.
- // TODO: Investigate how log this is held onto and try to keep that to a minimum.
+ // TODO: Investigate how long this is held onto and try to keep that to a minimum.
source = transformedImage;
return source;
}