diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 45d7d1270..3f7f1e562 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -1255,7 +1255,8 @@ internal sealed class PngEncoderCore : IDisposable Span attempt = attemptBuffer.GetSpan(); for (int y = 0; y < pixels.Height; y++) { - this.CollectAndFilterPixelRow(pixels.DangerousGetRowSpan(y), ref filter, ref attempt, quantized, y); + ReadOnlySpan rowSpan = pixels.DangerousGetRowSpan(y); + this.CollectAndFilterPixelRow(rowSpan, ref filter, ref attempt, quantized, y); deflateStream.Write(filter); this.SwapScanlineBuffers(); } @@ -1303,7 +1304,8 @@ internal sealed class PngEncoderCore : IDisposable // Encode data // Note: quantized parameter not used // Note: row parameter not used - this.CollectAndFilterPixelRow(block, ref filter, ref attempt, null, -1); + ReadOnlySpan blockSpan = block; + this.CollectAndFilterPixelRow(blockSpan, ref filter, ref attempt, null, -1); deflateStream.Write(filter); this.SwapScanlineBuffers();