// -------------------------------------------------------------------------------------------------------------------- // // 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; using ImageProcessor.Imaging.Quantizers; using ImageProcessor.Imaging.Quantizers.WuQuantizer; /// /// Provides the necessary information to support png images. /// public class PngFormat : FormatBase, IQuantizableImageFormat { /// /// The quantizer for reducing the image palette. /// private IQuantizer quantizer = new WuQuantizer(); /// /// Gets the file headers. /// public override byte[][] FileHeaders { get { return new[] { new byte[] { 137, 80, 78, 71 } }; } } /// /// Gets the list of file extensions. /// 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; } } /// /// Gets or sets the quantizer for reducing the image palette. /// public IQuantizer Quantizer { get { return this.quantizer; } set { this.quantizer = value; } } /// /// Gets or sets the color count. /// public int ColorCount { get; set; } /// /// Saves the current image to the specified output stream. /// /// The to save the image information to. /// The to save. /// /// The . /// public override Image Save(Stream stream, Image image) { if (this.IsIndexed) { image = this.Quantizer.Quantize(image); } return base.Save(stream, 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 = this.Quantizer.Quantize(image); } return base.Save(path, image); } } }