// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageProcessor.Formats { using System; using System.IO; /// /// Image decoder for generating an image out of a Windows bitmap stream. /// /// /// Does not support the following formats at the moment: /// /// JPG /// PNG /// RLE4 /// RLE8 /// BitFields /// /// Formats will be supported in a later releases. We advise always /// to use only 24 Bit Windows bitmaps. /// public class BmpDecoder : IImageDecoder { /// /// Gets the size of the header for this image type. /// /// The size of the header. public int HeaderSize => 2; /// /// Returns a value indicating whether the supports the specified /// file header. /// /// The containing the file extension. /// /// True if the decoder supports the file extension; otherwise, false. /// public bool IsSupportedFileExtension(string extension) { Guard.NotNullOrEmpty(extension, "extension"); extension = extension.StartsWith(".") ? extension.Substring(1) : extension; return extension.Equals("BMP", StringComparison.OrdinalIgnoreCase) || extension.Equals("DIP", StringComparison.OrdinalIgnoreCase); } /// /// Returns a value indicating whether the supports the specified /// file header. /// /// The containing the file header. /// /// True if the decoder supports the file header; otherwise, false. /// public bool IsSupportedFileFormat(byte[] header) { bool isBmp = false; if (header.Length >= 2) { isBmp = header[0] == 0x42 && // B header[1] == 0x4D; // M } return isBmp; } /// /// Decodes the image from the specified stream to the . /// /// The to decode to. /// The containing image data. public void Decode(Image image, Stream stream) { new BmpDecoderCore().Decode(image, stream); } } }