|
|
|
@ -25,13 +25,11 @@ namespace ImageProcessor.Imaging.Formats |
|
|
|
/// <summary>
|
|
|
|
/// Encodes multiple images as an animated gif to a stream.
|
|
|
|
/// <remarks>
|
|
|
|
/// 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 <see href="http://github.com/DataDink/Bumpkit/blob/master/BumpKit/BumpKit/GifEncoder.cs"/>
|
|
|
|
/// </remarks>
|
|
|
|
/// </summary>
|
|
|
|
public class GifEncoder : IDisposable |
|
|
|
public class GifEncoder |
|
|
|
{ |
|
|
|
#region Constants
|
|
|
|
/// <summary>
|
|
|
|
@ -127,19 +125,6 @@ namespace ImageProcessor.Imaging.Formats |
|
|
|
/// </summary>
|
|
|
|
private int? height; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A value indicating whether this instance of the given entity has been disposed.
|
|
|
|
/// </summary>
|
|
|
|
/// <value><see langword="true"/> if this instance has been disposed; otherwise, <see langword="false"/>.</value>
|
|
|
|
/// <remarks>
|
|
|
|
/// 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.
|
|
|
|
/// </remarks>
|
|
|
|
private bool isDisposed; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The is first image.
|
|
|
|
/// </summary>
|
|
|
|
@ -176,24 +161,6 @@ namespace ImageProcessor.Imaging.Formats |
|
|
|
this.height = height; |
|
|
|
this.repeatCount = repeatCount; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Finalizes an instance of the <see cref="GifEncoder"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// 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.
|
|
|
|
/// </remarks>
|
|
|
|
~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; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Disposes the object and frees resources for the Garbage Collector.
|
|
|
|
/// </summary>
|
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Saves the completed gif to an <see cref="Image"/>
|
|
|
|
/// </summary>
|
|
|
|
@ -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
|
|
|
|
/// <summary>
|
|
|
|
/// Disposes the object and frees resources for the Garbage Collector.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="disposing">
|
|
|
|
/// If true, the object gets disposed.
|
|
|
|
/// </param>
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Writes the header block of the animated gif to the stream.
|
|
|
|
/// </summary>
|
|
|
|
|