Skip to content
io
bmp
read_bmp

read_bmp

Mojo function 🡭

read_bmp

fn def read_bmp(path: String) -> Canvas

Read an uncompressed 24- or 32-bit BMP into a new Canvas.

Handles both row orders. BMP conventionally stores rows bottom-up, which is what write_bmp emits, but a negative height field means top-down and several common tools write that – reading only one order would silently return vertically mirrored images from the other.

Every returned pixel is opaque; see this module’s docstring for why a 32-bit file’s fourth byte is not trusted as alpha.

Args:

  • path (String): File to read.

Returns:

Canvas: A Canvas holding the decoded image.

Raises:

Error: The file is missing, truncated, not a BMP, or uses a compression or bit depth outside the supported set.