// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // // // Provides the necessary information to support png images. // // -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Imaging.Formats { using System.Drawing; using System.Drawing.Imaging; using System.IO; /// /// Provides the necessary information to support png images. /// public class PngFormat : FormatBase { /// /// Gets the file headers. /// public override byte[][] FileHeaders { get { return new[] { new byte[] { 137, 80, 78, 71 } }; } } /// /// Gets the list of file extensions. /// Obviously png8 isn't a valid file extension but it's a neat way to /// add the value to the format method detection. /// public override string[] FileExtensions { get { return new[] { "png" }; } } /// /// Gets the standard identifier used on the Internet to indicate the type of data that a file contains. /// public override string MimeType { get { return "image/png"; } } /// /// Gets the . /// public override ImageFormat ImageFormat { get { return ImageFormat.Png; } } /// /// Saves the current image to the specified output stream. /// /// The to save the image information to. /// The to save. /// /// The . /// public override Image Save(MemoryStream memoryStream, Image image) { if (this.IsIndexed) { image = new OctreeQuantizer(255, 8).Quantize(image); } return base.Save(memoryStream, image); } /// /// Saves the current image to the specified file path. /// /// The path to save the image to. /// The /// to save. /// /// The . /// public override Image Save(string path, Image image) { if (this.IsIndexed) { image = new OctreeQuantizer(255, 8).Quantize(image); } return base.Save(path, image); } } }