From 623a5342bbefafc2bb61b738989ae0cf882b91e9 Mon Sep 17 00:00:00 2001 From: James South Date: Mon, 23 Jun 2014 13:57:39 +0100 Subject: [PATCH] Fixing stupid image disposal. Former-commit-id: 73cf3d24165255ab5dcf13e5d3f631ab8bcd477d --- .../Imaging/Formats/FormatUtilities.cs | 6 +++--- src/ImageProcessor/Processors/Alpha.cs | 7 ++----- src/ImageProcessor/Processors/AutoRotate.cs | 7 ++----- .../Processors/BackgroundColor.cs | 7 ++----- src/ImageProcessor/Processors/Brightness.cs | 7 ++----- src/ImageProcessor/Processors/Contrast.cs | 7 ++----- src/ImageProcessor/Processors/Crop.cs | 10 ++------- src/ImageProcessor/Processors/Filter.cs | 10 ++------- src/ImageProcessor/Processors/Flip.cs | 7 ++----- src/ImageProcessor/Processors/Format.cs | 1 - src/ImageProcessor/Processors/GaussianBlur.cs | 7 ++----- .../Processors/GaussianSharpen.cs | 7 ++----- src/ImageProcessor/Processors/Quality.cs | 5 ----- src/ImageProcessor/Processors/Resize.cs | 7 ++----- src/ImageProcessor/Processors/Rotate.cs | 7 ++----- .../Processors/RoundedCorners.cs | 10 ++------- src/ImageProcessor/Processors/Saturation.cs | 11 ++-------- src/ImageProcessor/Processors/Tint.cs | 9 ++------ src/ImageProcessor/Processors/Vignette.cs | 7 ++----- src/ImageProcessor/Processors/Watermark.cs | 7 ++----- src/ImageProcessorConsole/Program.cs | 21 ++++++++++++------- 21 files changed, 50 insertions(+), 117 deletions(-) diff --git a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs index 39ea4cfd1..a382e6449 100644 --- a/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs +++ b/src/ImageProcessor/Imaging/Formats/FormatUtilities.cs @@ -138,19 +138,19 @@ namespace ImageProcessor.Imaging.Formats int index = 0; List gifFrames = new List(); - 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); } diff --git a/src/ImageProcessor/Processors/Alpha.cs b/src/ImageProcessor/Processors/Alpha.cs index 4d98e8b37..e921233e8 100644 --- a/src/ImageProcessor/Processors/Alpha.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/AutoRotate.cs b/src/ImageProcessor/Processors/AutoRotate.cs index 521d0c2e9..1fcf81f48 100644 --- a/src/ImageProcessor/Processors/AutoRotate.cs +++ b/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; diff --git a/src/ImageProcessor/Processors/BackgroundColor.cs b/src/ImageProcessor/Processors/BackgroundColor.cs index 8ba8bf2a2..6d785f1f3 100644 --- a/src/ImageProcessor/Processors/BackgroundColor.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/Brightness.cs b/src/ImageProcessor/Processors/Brightness.cs index 0e3fed717..4df039a07 100644 --- a/src/ImageProcessor/Processors/Brightness.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/Contrast.cs b/src/ImageProcessor/Processors/Contrast.cs index f1ceb79ed..a6fec199d 100644 --- a/src/ImageProcessor/Processors/Contrast.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/Crop.cs b/src/ImageProcessor/Processors/Crop.cs index 85bb9886c..2b0f3c417 100644 --- a/src/ImageProcessor/Processors/Crop.cs +++ b/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 /// /// 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; diff --git a/src/ImageProcessor/Processors/Filter.cs b/src/ImageProcessor/Processors/Filter.cs index ecd6700f1..f98a041c0 100644 --- a/src/ImageProcessor/Processors/Filter.cs +++ b/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 /// /// 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; diff --git a/src/ImageProcessor/Processors/Flip.cs b/src/ImageProcessor/Processors/Flip.cs index a93d330f3..5f57e5c9c 100644 --- a/src/ImageProcessor/Processors/Flip.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/Format.cs b/src/ImageProcessor/Processors/Format.cs index 2f67ad71a..2f3af85a1 100644 --- a/src/ImageProcessor/Processors/Format.cs +++ b/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; diff --git a/src/ImageProcessor/Processors/GaussianBlur.cs b/src/ImageProcessor/Processors/GaussianBlur.cs index 60abedec1..3e2959094 100644 --- a/src/ImageProcessor/Processors/GaussianBlur.cs +++ b/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; diff --git a/src/ImageProcessor/Processors/GaussianSharpen.cs b/src/ImageProcessor/Processors/GaussianSharpen.cs index 94c697362..2949a899a 100644 --- a/src/ImageProcessor/Processors/GaussianSharpen.cs +++ b/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; diff --git a/src/ImageProcessor/Processors/Quality.cs b/src/ImageProcessor/Processors/Quality.cs index 28bb445fb..9d53ccb9e 100644 --- a/src/ImageProcessor/Processors/Quality.cs +++ b/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 - /// /// Encapsulates methods to change the quality component of the image. /// diff --git a/src/ImageProcessor/Processors/Resize.cs b/src/ImageProcessor/Processors/Resize.cs index cce1177e2..f52587492 100644 --- a/src/ImageProcessor/Processors/Resize.cs +++ b/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; diff --git a/src/ImageProcessor/Processors/Rotate.cs b/src/ImageProcessor/Processors/Rotate.cs index ccf23514a..4e1bd8142 100644 --- a/src/ImageProcessor/Processors/Rotate.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/RoundedCorners.cs b/src/ImageProcessor/Processors/RoundedCorners.cs index 89e4b683c..ebd26ef24 100644 --- a/src/ImageProcessor/Processors/RoundedCorners.cs +++ b/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 /// /// 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; diff --git a/src/ImageProcessor/Processors/Saturation.cs b/src/ImageProcessor/Processors/Saturation.cs index 09fae902c..f0e245821 100644 --- a/src/ImageProcessor/Processors/Saturation.cs +++ b/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 - /// /// Encapsulates methods to change the saturation component of the image. /// @@ -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; diff --git a/src/ImageProcessor/Processors/Tint.cs b/src/ImageProcessor/Processors/Tint.cs index 939cecb9c..9943a0cc3 100644 --- a/src/ImageProcessor/Processors/Tint.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/Vignette.cs b/src/ImageProcessor/Processors/Vignette.cs index f600f35ed..9d4f12241 100644 --- a/src/ImageProcessor/Processors/Vignette.cs +++ b/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; /// @@ -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; diff --git a/src/ImageProcessor/Processors/Watermark.cs b/src/ImageProcessor/Processors/Watermark.cs index d6e9a97fe..9ce4771ff 100644 --- a/src/ImageProcessor/Processors/Watermark.cs +++ b/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; diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs index fd5492fa8..44f7e96ff 100644 --- a/src/ImageProcessorConsole/Program.cs +++ b/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 + /// + /// The program. + /// + public class Program { - static void Main(string[] args) + /// + /// The main routine. + /// + /// + /// The args. + /// + 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))); } } }