diff --git a/src/ImageSharp/Image/ImageFrameCollection.cs b/src/ImageSharp/Image/ImageFrameCollection.cs index b29fdc5115..3e9bb03435 100644 --- a/src/ImageSharp/Image/ImageFrameCollection.cs +++ b/src/ImageSharp/Image/ImageFrameCollection.cs @@ -24,7 +24,9 @@ internal ImageFrameCollection(Image parent, int width, int height) Guard.NotNull(parent, nameof(parent)); this.parent = parent; - this.AddFrame(new ImageFrame(width, height)); + + // Frames are already cloned within the caller + this.frames.Add(new ImageFrame(width, height)); } internal ImageFrameCollection(Image parent, IEnumerable> frames) @@ -33,9 +35,12 @@ internal ImageFrameCollection(Image parent, IEnumerable f in frames) { - this.AddFrame(f); + this.ValidateFrame(f); + this.frames.Add(f); } } diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 85e1aa858c..482971e540 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -143,9 +143,8 @@ public void Save(Stream stream, IImageEncoder encoder) /// Returns a new image with all the same metadata as the original. public Image Clone() { - IEnumerable> frames = this.frames.Select(x => x.Clone()).ToArray(); - - return new Image(this.configuration, this.MetaData.Clone(), frames); + IEnumerable> clonedFrames = this.frames.Select(x => x.Clone()); + return new Image(this.configuration, this.MetaData.Clone(), clonedFrames); } /// @@ -162,8 +161,8 @@ public override string ToString() public Image CloneAs() where TPixel2 : struct, IPixel { - IEnumerable> frames = this.frames.Select(x => x.CloneAs()).ToArray(); - var target = new Image(this.configuration, this.MetaData, frames); + IEnumerable> clonedFrames = this.frames.Select(x => x.CloneAs()); + var target = new Image(this.configuration, this.MetaData.Clone(), clonedFrames); return target; }