diff --git a/src/Magick.NET/Helpers/TemporaryDefines.cs b/src/Magick.NET/Helpers/TemporaryDefines.cs index af71c2d680..b99e91efc5 100644 --- a/src/Magick.NET/Helpers/TemporaryDefines.cs +++ b/src/Magick.NET/Helpers/TemporaryDefines.cs @@ -9,10 +9,10 @@ namespace ImageMagick; internal sealed class TemporaryDefines : IDisposable { - private readonly MagickImage _image; + private readonly IMagickImage _image; private readonly List _names = new(); - public TemporaryDefines(MagickImage image) + public TemporaryDefines(IMagickImage image) { _image = image; } diff --git a/src/Magick.NET/MagickImageCollection.cs b/src/Magick.NET/MagickImageCollection.cs index 6911280251..d621352801 100644 --- a/src/Magick.NET/MagickImageCollection.cs +++ b/src/Magick.NET/MagickImageCollection.cs @@ -442,19 +442,14 @@ public void Complex(IComplexSettings complexSettings) { Throw.IfNull(nameof(complexSettings), complexSettings); - using var imageAttacher = new TemporaryImageAttacher(_images); + using var temporaryDefines = new TemporaryDefines(_images[0]); if (complexSettings.SignalToNoiseRatio is not null) - _images[0].SetArtifact("complex:snr", complexSettings.SignalToNoiseRatio.Value.ToString(CultureInfo.InvariantCulture)); + temporaryDefines.SetArtifact("complex:snr", complexSettings.SignalToNoiseRatio.Value.ToString(CultureInfo.InvariantCulture)); + using var imageAttacher = new TemporaryImageAttacher(_images); var images = _nativeInstance.Complex(_images[0], complexSettings.ComplexOperator); ReplaceImages(images); - - if (complexSettings.SignalToNoiseRatio is not null) - { - foreach (var image in _images) - image.RemoveArtifact("complex:snr"); - } } ///