encodeBmp

Encode bitmap as a BMP: 24-bit BI_RGB when it is opaque, or 32-bit BI_BITFIELDS under a V4 header when it carries alpha (plain 32-bit BMP alpha is officially "reserved", and half the world's readers discard it). Uncompressed and lossless either way.


Encode bitmap as a BMP of the depth options gives (#184): a palette of 1, 4 or 8 bits, with BI_RLE4 or BI_RLE8 on request, 16-bit 5-5-5, 24-bit BI_RGB or 32-bit BI_BITFIELDS with alpha. BmpEncodeOptions() gives what encodeBmp without options gives, byte for byte. Every depth but 16 is lossless.

Throws

if bitmap has alpha and the depth is not 32, or has more colours than a palette depth holds


encodeBmp with options that also embeds metadata's ICC profile (#186): with a profile, the header is a BITMAPV5HEADER whose colour space is PROFILE_EMBEDDED, and the profile follows the pixels; without one, the file is what the overload without metadata writes. A BMP has no place for EXIF or XMP, so those are left out. readMetadata reads the profile back.

Throws

as the overload without metadata does, or if the file with its profile would pass 2 GB