// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) James South. // Licensed under the Apache License, Version 2.0. // // // The supported format base implement this class when building a supported format. // // -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Imaging.Formats { using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; /// /// The supported format base. Implement this class when building a supported format. /// public abstract class FormatBase : ISupportedImageFormat { /// /// Gets the file headers. /// public abstract byte[][] FileHeaders { get; } /// /// Gets the list of file extensions. /// public abstract string[] FileExtensions { get; } /// /// Gets the standard identifier used on the Internet to indicate the type of data that a file contains. /// public abstract string MimeType { get; } /// /// Gets the default file extension. /// public string DefaultExtension { get { return this.MimeType.Replace("image/", string.Empty); } } /// /// Gets the file format of the image. /// public abstract ImageFormat ImageFormat { get; } /// /// Gets or sets a value indicating whether the image format is indexed. /// public bool IsIndexed { get; set; } /// /// Gets or sets a value indicating whether the image format is animated. /// public bool IsAnimated { get; set; } /// /// Gets or sets the quality of output for images. /// public int Quality { get; set; } /// /// Applies the given processor the current image. /// /// The processor delegate. /// The . public virtual void ApplyProcessor(Func processor, ImageFactory factory) { factory.Image = processor.Invoke(factory); } /// /// Decodes the image to process. /// /// /// The containing the image information. /// /// /// The the . /// public virtual Image Load(Stream stream) { return Image.FromStream(stream, true); } /// /// Saves the current image to the specified output stream. /// /// The to save the image information to. /// The to save. /// /// The . /// public virtual Image Save(MemoryStream memoryStream, Image image) { image.Save(memoryStream, this.ImageFormat); memoryStream.Position = 0; return image; } /// /// Saves the current image to the specified file path. /// /// The path to save the image to. /// The /// to save. /// /// The . /// public virtual Image Save(string path, Image image) { image.Save(path, this.ImageFormat); return image; } } }