From 2e330649fa15c2aa35f02fe407ee80490cf7ebac Mon Sep 17 00:00:00 2001 From: dirk Date: Sat, 13 Aug 2016 18:02:53 +0200 Subject: [PATCH] Added method to copy the properties of an image. Former-commit-id: 126b2f90afc19b367669116a5610fcbd3c252726 Former-commit-id: f2820929b2c9f92b7cb2ced52b674367f70eeba9 Former-commit-id: 988552a23146160a96a521b56b0016fb32dbc0e1 --- src/ImageProcessorCore/Image/Image.cs | 31 +++++++++++++------ src/ImageProcessorCore/Image/ImageBase.cs | 15 +++++++-- .../Image/ImageExtensions.cs | 15 +++------ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/ImageProcessorCore/Image/Image.cs b/src/ImageProcessorCore/Image/Image.cs index ff91e2372..a9377636d 100644 --- a/src/ImageProcessorCore/Image/Image.cs +++ b/src/ImageProcessorCore/Image/Image.cs @@ -87,15 +87,7 @@ namespace ImageProcessorCore } } - this.RepeatCount = other.RepeatCount; - this.HorizontalResolution = other.HorizontalResolution; - this.VerticalResolution = other.VerticalResolution; - this.CurrentImageFormat = other.CurrentImageFormat; - - if (other.ExifProfile != null) - { - this.ExifProfile = new ExifProfile(other.ExifProfile); - } + this.CopyProperties(other); } /// @@ -251,6 +243,27 @@ namespace ImageProcessorCore } } + /// + /// Copies the properties from the other . + /// + /// + /// The other to copy the properties from. + /// + internal void CopyProperties(Image other) + { + base.CopyProperties(other); + + this.HorizontalResolution = other.HorizontalResolution; + this.VerticalResolution = other.VerticalResolution; + this.CurrentImageFormat = other.CurrentImageFormat; + this.RepeatCount = other.RepeatCount; + + if (other.ExifProfile != null) + { + this.ExifProfile = new ExifProfile(other.ExifProfile); + } + } + /// /// Loads the image from the given stream. /// diff --git a/src/ImageProcessorCore/Image/ImageBase.cs b/src/ImageProcessorCore/Image/ImageBase.cs index adbe70d1b..095f9c362 100644 --- a/src/ImageProcessorCore/Image/ImageBase.cs +++ b/src/ImageProcessorCore/Image/ImageBase.cs @@ -59,8 +59,7 @@ namespace ImageProcessorCore this.Width = other.Width; this.Height = other.Height; - this.Quality = other.Quality; - this.FrameDelay = other.FrameDelay; + this.CopyProperties(other); // Copy the pixels. this.Pixels = new T[this.Width * this.Height]; @@ -145,5 +144,17 @@ namespace ImageProcessorCore /// public abstract IPixelAccessor Lock(); + + /// + /// Copies the properties from the other . + /// + /// + /// The other to copy the properties from. + /// + protected void CopyProperties(ImageBase other) + { + this.Quality = other.Quality; + this.FrameDelay = other.FrameDelay; + } } } diff --git a/src/ImageProcessorCore/Image/ImageExtensions.cs b/src/ImageProcessorCore/Image/ImageExtensions.cs index b9ff38a7c..c3aaf2f68 100644 --- a/src/ImageProcessorCore/Image/ImageExtensions.cs +++ b/src/ImageProcessorCore/Image/ImageExtensions.cs @@ -171,16 +171,11 @@ namespace ImageProcessorCore { Image transformedImage = clone ? new Image(source) - : new Image - { - // Several properties require copying - FrameDelay = source.FrameDelay, - Quality = source.Quality, - HorizontalResolution = source.HorizontalResolution, - VerticalResolution = source.VerticalResolution, - CurrentImageFormat = source.CurrentImageFormat, - RepeatCount = source.RepeatCount - }; + : new Image(); + + // Several properties still require copying + if (!clone) + transformedImage.CopyProperties(source); action(source, transformedImage);