//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp.Formats
{
using System;
using System.IO;
///
/// Image encoder for writing an image to a stream as a Windows bitmap.
///
/// The encoder can currently only write 24-bit rgb images to streams.
public class BmpEncoder : IImageEncoder
{
///
/// Gets or sets the quality of output for images.
///
/// Bitmap is a lossless format so this is not used in this encoder.
public int Quality { get; set; }
///
public string MimeType => "image/bmp";
///
public string Extension => "bmp";
///
/// Gets or sets the number of bits per pixel.
///
public BmpBitsPerPixel BitsPerPixel { get; set; } = BmpBitsPerPixel.Pixel24;
///
public bool IsSupportedFileExtension(string extension)
{
Guard.NotNullOrEmpty(extension, nameof(extension));
extension = extension.StartsWith(".") ? extension.Substring(1) : extension;
return extension.Equals(this.Extension, StringComparison.OrdinalIgnoreCase)
|| extension.Equals("dip", StringComparison.OrdinalIgnoreCase);
}
///
public void Encode(Image image, Stream stream)
where TColor : struct, IPackedPixel
where TPacked : struct
{
BmpEncoderCore encoder = new BmpEncoderCore();
encoder.Encode(image, stream, this.BitsPerPixel);
}
}
}