Browse Source

Fixing stupid image disposal.

Former-commit-id: 73cf3d24165255ab5dcf13e5d3f631ab8bcd477d
pull/17/head
James South 12 years ago
parent
commit
623a5342bb
  1. 6
      src/ImageProcessor/Imaging/Formats/FormatUtilities.cs
  2. 7
      src/ImageProcessor/Processors/Alpha.cs
  3. 7
      src/ImageProcessor/Processors/AutoRotate.cs
  4. 7
      src/ImageProcessor/Processors/BackgroundColor.cs
  5. 7
      src/ImageProcessor/Processors/Brightness.cs
  6. 7
      src/ImageProcessor/Processors/Contrast.cs
  7. 10
      src/ImageProcessor/Processors/Crop.cs
  8. 10
      src/ImageProcessor/Processors/Filter.cs
  9. 7
      src/ImageProcessor/Processors/Flip.cs
  10. 1
      src/ImageProcessor/Processors/Format.cs
  11. 7
      src/ImageProcessor/Processors/GaussianBlur.cs
  12. 7
      src/ImageProcessor/Processors/GaussianSharpen.cs
  13. 5
      src/ImageProcessor/Processors/Quality.cs
  14. 7
      src/ImageProcessor/Processors/Resize.cs
  15. 7
      src/ImageProcessor/Processors/Rotate.cs
  16. 10
      src/ImageProcessor/Processors/RoundedCorners.cs
  17. 11
      src/ImageProcessor/Processors/Saturation.cs
  18. 9
      src/ImageProcessor/Processors/Tint.cs
  19. 7
      src/ImageProcessor/Processors/Vignette.cs
  20. 7
      src/ImageProcessor/Processors/Watermark.cs
  21. 21
      src/ImageProcessorConsole/Program.cs

6
src/ImageProcessor/Imaging/Formats/FormatUtilities.cs

@ -138,19 +138,19 @@ namespace ImageProcessor.Imaging.Formats
int index = 0;
List<GifFrame> gifFrames = new List<GifFrame>();
for (int f = 0; f < frameCount; f++)
for (int i = 0; i < frameCount; i++)
{
int thisDelay = BitConverter.ToInt32(image.GetPropertyItem(20736).Value, index);
int toAddDelay = thisDelay * 10 < 20 ? 20 : thisDelay * 10; // Minimum delay is 20 ms
// Find the frame
image.SelectActiveFrame(frameDimension, f);
image.SelectActiveFrame(frameDimension, i);
// TODO: Get positions.
gifFrames.Add(new GifFrame { Delay = toAddDelay, Image = (Image)image.Clone() });
// Reset the position.
if (f == last)
if (i == last)
{
image.SelectActiveFrame(frameDimension, 0);
}

7
src/ImageProcessor/Processors/Alpha.cs

@ -14,7 +14,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -95,15 +94,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/AutoRotate.cs

@ -14,7 +14,6 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging;
@ -97,15 +96,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/BackgroundColor.cs

@ -13,7 +13,6 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -72,15 +71,13 @@ namespace ImageProcessor.Processors
image = newImage;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/Brightness.cs

@ -14,7 +14,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -100,15 +99,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/Contrast.cs

@ -14,7 +14,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -97,15 +96,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

10
src/ImageProcessor/Processors/Crop.cs

@ -10,17 +10,13 @@
namespace ImageProcessor.Processors
{
#region Using
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging;
#endregion
/// <summary>
/// Crops an image to the given directions.
@ -137,15 +133,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

10
src/ImageProcessor/Processors/Filter.cs

@ -10,16 +10,12 @@
namespace ImageProcessor.Processors
{
#region Using
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging.Filters;
#endregion
/// <summary>
/// Encapsulates methods with which to add filters to an image.
@ -78,15 +74,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/Flip.cs

@ -13,7 +13,6 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -75,15 +74,13 @@ namespace ImageProcessor.Processors
image = newImage;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

1
src/ImageProcessor/Processors/Format.cs

@ -13,7 +13,6 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging.Formats;

7
src/ImageProcessor/Processors/GaussianBlur.cs

@ -13,7 +13,6 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging;
@ -66,15 +65,13 @@ namespace ImageProcessor.Processors
image = newImage;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/GaussianSharpen.cs

@ -13,7 +13,6 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging;
@ -66,15 +65,13 @@ namespace ImageProcessor.Processors
image = newImage;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

5
src/ImageProcessor/Processors/Quality.cs

@ -10,16 +10,11 @@
namespace ImageProcessor.Processors
{
#region Using
using System;
using System.Collections.Generic;
using System.Drawing;
using ImageProcessor.Core.Common.Exceptions;
#endregion
/// <summary>
/// Encapsulates methods to change the quality component of the image.
/// </summary>

7
src/ImageProcessor/Processors/Resize.cs

@ -17,7 +17,6 @@ namespace ImageProcessor.Processors
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging;
@ -362,15 +361,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/Rotate.cs

@ -14,7 +14,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -78,15 +77,13 @@ namespace ImageProcessor.Processors
image = newImage;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

10
src/ImageProcessor/Processors/RoundedCorners.cs

@ -10,16 +10,12 @@
namespace ImageProcessor.Processors
{
#region Using
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging;
#endregion
/// <summary>
/// Encapsulates methods to add rounded corners to an image.
@ -84,15 +80,13 @@ namespace ImageProcessor.Processors
image = newImage;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

11
src/ImageProcessor/Processors/Saturation.cs

@ -10,17 +10,12 @@
namespace ImageProcessor.Processors
{
#region Using
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using ImageProcessor.Core.Common.Exceptions;
#endregion
/// <summary>
/// Encapsulates methods to change the saturation component of the image.
/// </summary>
@ -132,15 +127,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

9
src/ImageProcessor/Processors/Tint.cs

@ -15,7 +15,6 @@ namespace ImageProcessor.Processors
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -86,19 +85,15 @@ namespace ImageProcessor.Processors
image = newImage;
}
}
return image;
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/Vignette.cs

@ -14,7 +14,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using ImageProcessor.Core.Common.Exceptions;
/// <summary>
@ -117,15 +116,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

7
src/ImageProcessor/Processors/Watermark.cs

@ -14,7 +14,6 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using ImageProcessor.Core.Common.Exceptions;
using ImageProcessor.Imaging;
@ -133,15 +132,13 @@ namespace ImageProcessor.Processors
}
}
catch (Exception ex)
{
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
finally
{
if (newImage != null)
{
newImage.Dispose();
}
throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
}
return image;

21
src/ImageProcessorConsole/Program.cs

@ -1,16 +1,22 @@

namespace ImageProcessorConsole
namespace ImageProcessorConsole
{
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using ImageProcessor;
class Program
/// <summary>
/// The program.
/// </summary>
public class Program
{
static void Main(string[] args)
/// <summary>
/// The main routine.
/// </summary>
/// <param name="args">
/// The args.
/// </param>
public static void Main(string[] args)
{
string path = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath;
// ReSharper disable once AssignNullToNotNullAttribute
@ -33,12 +39,11 @@ namespace ImageProcessorConsole
using (ImageFactory imageFactory = new ImageFactory())
{
Size size = new Size(200, 200);
ImageFormat format = ImageFormat.Gif;
// Load, resize, set the format and quality and save an image.
imageFactory.Load(inStream)
.Constrain(size)
.Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name.TrimEnd(".gif".ToCharArray()) + ".jpg")));
.Save(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path), @"..\..\images\output", fileInfo.Name)));
}
}
}

Loading…
Cancel
Save