diff --git a/src/ImageProcessor/Imaging/Formats/GifEncoder.cs b/src/ImageProcessor/Imaging/Formats/GifEncoder.cs
index 9f107aea8..249d5d12c 100644
--- a/src/ImageProcessor/Imaging/Formats/GifEncoder.cs
+++ b/src/ImageProcessor/Imaging/Formats/GifEncoder.cs
@@ -25,13 +25,11 @@ namespace ImageProcessor.Imaging.Formats
///
/// Encodes multiple images as an animated gif to a stream.
///
- /// Always wire this up in a using block.
- /// Disposing the encoder will complete the file.
/// Uses default .NET GIF encoding and adds animation headers.
/// Adapted from
///
///
- public class GifEncoder : IDisposable
+ public class GifEncoder
{
#region Constants
///
@@ -127,19 +125,6 @@ namespace ImageProcessor.Imaging.Formats
///
private int? height;
- ///
- /// A value indicating whether this instance of the given entity has been disposed.
- ///
- /// if this instance has been disposed; otherwise, .
- ///
- /// If the entity is disposed, it must not be disposed a second
- /// time. The isDisposed field is set the first time the entity
- /// is disposed. If the isDisposed field is true, then the Dispose()
- /// method will not dispose again. This help not to prolong the entity's
- /// life in the Garbage Collector.
- ///
- private bool isDisposed;
-
///
/// The is first image.
///
@@ -176,24 +161,6 @@ namespace ImageProcessor.Imaging.Formats
this.height = height;
this.repeatCount = repeatCount;
}
-
- ///
- /// Finalizes an instance of the class.
- ///
- ///
- /// Use C# destructor syntax for finalization code.
- /// This destructor will run only if the Dispose method
- /// does not get called.
- /// It gives your base class the opportunity to finalize.
- /// Do not provide destructors in types derived from this class.
- ///
- ~GifEncoder()
- {
- // Do not re-create Dispose clean-up code here.
- // Calling Dispose(false) is optimal in terms of
- // readability and maintainability.
- this.Dispose(false);
- }
#endregion
#region Public Methods and Operators
@@ -221,21 +188,6 @@ namespace ImageProcessor.Imaging.Formats
this.isFirstImage = false;
}
- ///
- /// Disposes the object and frees resources for the Garbage Collector.
- ///
- public void Dispose()
- {
- this.Dispose(true);
-
- // This object will be cleaned up by the Dispose method.
- // Therefore, you should call GC.SupressFinalize to
- // take this object off the finalization queue
- // and prevent finalization code for this object
- // from executing a second time.
- GC.SuppressFinalize(this);
- }
-
///
/// Saves the completed gif to an
///
@@ -249,35 +201,12 @@ namespace ImageProcessor.Imaging.Formats
this.imageStream.Flush();
this.imageStream.Position = 0;
byte[] bytes = this.imageStream.ToArray();
+ this.imageStream.Dispose();
return (Image)Converter.ConvertFrom(bytes);
}
#endregion
#region Methods
- ///
- /// Disposes the object and frees resources for the Garbage Collector.
- ///
- ///
- /// If true, the object gets disposed.
- ///
- protected virtual void Dispose(bool disposing)
- {
- if (this.isDisposed)
- {
- return;
- }
-
- if (disposing)
- {
- this.imageStream.Dispose();
- }
-
- // Call the appropriate methods to clean up
- // unmanaged resources here.
- // Note disposing is done.
- this.isDisposed = true;
- }
-
///
/// Writes the header block of the animated gif to the stream.
///
diff --git a/src/ImageProcessor/Imaging/Formats/GifFormat.cs b/src/ImageProcessor/Imaging/Formats/GifFormat.cs
index 091db1037..c36457ae5 100644
--- a/src/ImageProcessor/Imaging/Formats/GifFormat.cs
+++ b/src/ImageProcessor/Imaging/Formats/GifFormat.cs
@@ -79,17 +79,15 @@ namespace ImageProcessor.Imaging.Formats
if (decoder.IsAnimated)
{
OctreeQuantizer quantizer = new OctreeQuantizer(255, 8);
- using (GifEncoder encoder = new GifEncoder(null, null, decoder.LoopCount))
+ GifEncoder encoder = new GifEncoder(null, null, decoder.LoopCount);
+ foreach (GifFrame frame in decoder.GifFrames)
{
- foreach (GifFrame frame in decoder.GifFrames)
- {
- factory.Image = frame.Image;
- frame.Image = quantizer.Quantize(processor.Invoke(factory));
- encoder.AddFrame(frame);
- }
-
- factory.Image = encoder.Save();
+ factory.Image = frame.Image;
+ frame.Image = quantizer.Quantize(processor.Invoke(factory));
+ encoder.AddFrame(frame);
}
+
+ factory.Image = encoder.Save();
}
else
{