diff --git a/src/ImageSharp/Formats/Png/PngConstants.cs b/src/ImageSharp/Formats/Png/PngConstants.cs index 8b4ad39f2..3b3b02884 100644 --- a/src/ImageSharp/Formats/Png/PngConstants.cs +++ b/src/ImageSharp/Formats/Png/PngConstants.cs @@ -25,5 +25,16 @@ namespace SixLabors.ImageSharp.Formats.Png /// The list of file extensions that equate to a png. /// public static readonly IEnumerable FileExtensions = new[] { "png" }; + + public static readonly byte[] HeaderBytes = { + 0x89, // Set the high bit. + 0x50, // P + 0x4E, // N + 0x47, // G + 0x0D, // Line ending CRLF + 0x0A, // Line ending CRLF + 0x1A, // EOF + 0x0A // LF + }; } } \ No newline at end of file diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index 892b00ea9..777ee1f54 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -167,17 +167,7 @@ namespace SixLabors.ImageSharp.Formats.Png this.width = image.Width; this.height = image.Height; - // Write the png header. - this.chunkDataBuffer[0] = 0x89; // Set the high bit. - this.chunkDataBuffer[1] = 0x50; // P - this.chunkDataBuffer[2] = 0x4E; // N - this.chunkDataBuffer[3] = 0x47; // G - this.chunkDataBuffer[4] = 0x0D; // Line ending CRLF - this.chunkDataBuffer[5] = 0x0A; // Line ending CRLF - this.chunkDataBuffer[6] = 0x1A; // EOF - this.chunkDataBuffer[7] = 0x0A; // LF - - stream.Write(this.chunkDataBuffer, 0, 8); + stream.Write(PngConstants.HeaderBytes, 0, PngConstants.HeaderBytes.Length); QuantizedFrame quantized = null; if (this.pngColorType == PngColorType.Palette) diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index 4dbd214a5..f97e115b7 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. using System.IO; -using System.IO.Compression; using System.Text; -using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.PixelFormats; using Xunit; // ReSharper disable InconsistentNaming