diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index 0ceb7566ef..d519fc1edb 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -16,17 +16,17 @@ namespace AvatarWithRoundedCorner using (var img = Image.Load("fb.jpg")) { // as generate returns a new IImage make sure we dispose of it - using (Image dest = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 20))) + using (Image dest = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 20))) { dest.Save("output/fb.png"); } - using (Image destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 100))) + using (Image destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 100))) { destRound.Save("output/fb-round.png"); } - using (Image destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 150))) + using (Image destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 150))) { destRound.Save("output/fb-rounder.png"); } diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index 07a3ae8c29..7154396dd9 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -70,7 +70,7 @@ namespace ImageSharp.Drawing.Processors { if (targetImage.Bounds.Size != this.Size) { - targetImage = disposableImage = this.Image.Generate(x => x.Resize(this.Size.Width, this.Size.Height)); + targetImage = disposableImage = this.Image.Clone(x => x.Resize(this.Size.Width, this.Size.Height)); } // Align start/end positions. diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index 2a9c3ccbef..a092b789b1 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -49,13 +49,13 @@ namespace ImageSharp } /// - /// Mutates the image by applying the operations to it. + /// Clones the current image mutating the clone by applying the operations to it. /// /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. /// Anew Image which has teh data from the but with the applied. - public static Image Generate(this Image source, Action> operations) + public static Image Clone(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); @@ -68,13 +68,13 @@ namespace ImageSharp } /// - /// Mutates the image by applying the operations to it. + /// Clones the current image mutating the clone by applying the operations to it. /// /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. /// Anew Image which has teh data from the but with the applied. - public static Image Generate(this Image source, params IImageProcessor[] operations) + public static Image Clone(this Image source, params IImageProcessor[] operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); @@ -87,7 +87,7 @@ namespace ImageSharp } /// - /// Mutates the image by applying the operations to it. + /// Queues up a simple operation that provides access to the mutatable image. /// /// The pixel format. /// The image to rotate, flip, or both. diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 13b8655211..0dcb369059 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -250,6 +250,15 @@ namespace ImageSharp } #endif + /// + /// Clones the current image + /// + /// Returns a new image with all the same metadata as the original. + public Image Clone() + { + return new Image(this); + } + /// public override string ToString() { diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs index 46d4351ded..ea6d2e8052 100644 --- a/tests/ImageSharp.Tests/ImageComparer.cs +++ b/tests/ImageSharp.Tests/ImageComparer.cs @@ -138,7 +138,7 @@ namespace ImageSharp.Tests where TPixelA : struct, IPixel { byte[] buffer = new byte[3]; - using (Image img = source.Generate(x => x.Resize(scalingFactor, scalingFactor).Grayscale())) + using (Image img = source.Clone(x => x.Resize(scalingFactor, scalingFactor).Grayscale())) { using (PixelAccessor pixels = img.Lock()) {