diff --git a/src/ImageSharp/Formats/Tiff/Writers/TiffBiColorWriter{TPixel}.cs b/src/ImageSharp/Formats/Tiff/Writers/TiffBiColorWriter{TPixel}.cs index 662e729ef9..7c8720e07c 100644 --- a/src/ImageSharp/Formats/Tiff/Writers/TiffBiColorWriter{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/Writers/TiffBiColorWriter{TPixel}.cs @@ -26,7 +26,7 @@ public TiffBiColorWriter(ImageFrame image, MemoryAllocator memoryAllocat : base(image, memoryAllocator, configuration, entriesCollector) { // Convert image to black and white. - this.imageBlackWhite = new Image(configuration, new ImageMetadata(), new[] { image.Clone() }); + this.imageBlackWhite = new Image(configuration, new ImageMetadata(), image.Clone()); this.imageBlackWhite.Mutate(img => img.BinaryDither(KnownDitherings.FloydSteinberg)); } diff --git a/src/ImageSharp/ImageFrameCollection{TPixel}.cs b/src/ImageSharp/ImageFrameCollection{TPixel}.cs index da024c9176..8cf2726d81 100644 --- a/src/ImageSharp/ImageFrameCollection{TPixel}.cs +++ b/src/ImageSharp/ImageFrameCollection{TPixel}.cs @@ -38,6 +38,18 @@ internal ImageFrameCollection(Image parent, int width, int height, Memor this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, memorySource)); } + internal ImageFrameCollection(Image parent, ImageFrame frame) + { + Guard.NotNull(parent, nameof(parent)); + Guard.NotNull(frame, nameof(frame)); + + this.parent = parent; + + // Frame is already cloned by the caller + // this.ValidateFrame call can be omitted as it's the only frame + this.frames.Add(frame); + } + internal ImageFrameCollection(Image parent, IEnumerable> frames) { Guard.NotNull(parent, nameof(parent)); @@ -273,7 +285,7 @@ public override void MoveFrame(int sourceIndex, int destinationIndex) this.frames.Remove(frame); - return new Image(this.parent.GetConfiguration(), this.parent.Metadata.DeepClone(), new[] { frame }); + return new Image(this.parent.GetConfiguration(), this.parent.Metadata.DeepClone(), frame); } /// @@ -288,7 +300,7 @@ public override void MoveFrame(int sourceIndex, int destinationIndex) ImageFrame frame = this[index]; ImageFrame clonedFrame = frame.Clone(); - return new Image(this.parent.GetConfiguration(), this.parent.Metadata.DeepClone(), new[] { clonedFrame }); + return new Image(this.parent.GetConfiguration(), this.parent.Metadata.DeepClone(), clonedFrame); } /// diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index b43ff0422b..a8b07523a2 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -140,6 +140,19 @@ internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable< this.frames = new ImageFrameCollection(this, frames); } + /// + /// Initializes a new instance of the class + /// with the height and the width of the image. + /// + /// The configuration providing initialization code which allows extending the library. + /// The images metadata. + /// The frame that will be owned by this image instance. + internal Image(Configuration configuration, ImageMetadata metadata, ImageFrame frame) + : base(configuration, PixelTypeInfo.Create(), metadata, frame.Size()) + { + this.frames = new ImageFrameCollection(this, frame); + } + /// protected override ImageFrameCollection NonGenericFrameCollection => this.Frames; diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs index 675d6fe0d7..9e24dc6629 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor{TPixel}.cs @@ -39,7 +39,7 @@ protected override void BeforeImageApply() // TODO: This is clunky. We should add behavior enum to ExtractFrame. // All frames have be the same size so we only need to calculate the correct dimensions for the first frame - using (var temp = new Image(this.Configuration, this.Source.Metadata.DeepClone(), new[] { this.Source.Frames.RootFrame.Clone() })) + using (var temp = new Image(this.Configuration, this.Source.Metadata.DeepClone(), this.Source.Frames.RootFrame.Clone())) { Configuration configuration = this.Source.GetConfiguration();