/// <summary> /// Creates a deep clone of the current image. The clone is then mutated by the given operations. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image to clone.</param> /// <param name="operations">The operations to perform on the clone.</param> /// <returns>The new <see cref="Image{TPixel}"/></returns> public static Image <TPixel> Clone <TPixel>(this Image <TPixel> source, params IImageProcessor <TPixel>[] operations) where TPixel : struct, IPixel <TPixel> { Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); IInternalImageProcessingContext <TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider.CreateImageProcessingContext(source, false); operationsRunner.ApplyProcessors(operations); return(operationsRunner.Apply()); }
/// <summary> /// Mutates the source image by applying the operations to it. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image to mutate.</param> /// <param name="operations">The operations to perform on the source.</param> public static void Mutate <TPixel>(this Image <TPixel> source, params IImageProcessor[] operations) where TPixel : struct, IPixel <TPixel> { Guard.NotNull(source, nameof(source)); Guard.NotNull(operations, nameof(operations)); source.EnsureNotDisposed(); IInternalImageProcessingContext <TPixel> operationsRunner = source.GetConfiguration().ImageOperationsProvider .CreateImageProcessingContext(source, true); operationsRunner.ApplyProcessors(operations); }
/// <summary> /// Creates a deep clone of the current image. The clone is then mutated by the given operations. /// </summary> /// <typeparam name="TPixel">The pixel format.</typeparam> /// <param name="source">The image to clone.</param> /// <param name="configuration">The configuration which allows altering default behaviour or extending the library.</param> /// <param name="operations">The operations to perform on the clone.</param> /// <returns>The new <see cref="SixLabors.ImageSharp.Image{TPixel}"/></returns> public static Image <TPixel> Clone <TPixel>(this Image <TPixel> source, Configuration configuration, params IImageProcessor[] operations) where TPixel : struct, IPixel <TPixel> { Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(source, nameof(source)); Guard.NotNull(operations, nameof(operations)); source.EnsureNotDisposed(); IInternalImageProcessingContext <TPixel> operationsRunner = configuration.ImageOperationsProvider.CreateImageProcessingContext(configuration, source, false); operationsRunner.ApplyProcessors(operations); return(operationsRunner.GetResultImage()); }