BMP libraries for Python
- Pillow is the default choice. It reads 1 to 32-bit BMP and DIB files, including RLE4, RLE8, bit fields and OS/2 headers, and writes 1-bit, 8-bit, 24-bit and 32-bit files.
- OpenCV (
opencv-python) reads BMP into NumPy arrays and writes 8-bit gray, 24-bit and 32-bit BMP. Use it in computer vision code; remember it uses BGR channel order.
Writing a 24-bit BMP by hand needs only the struct module: a 54-byte header and BGR rows padded to 4 bytes (see the file structure).
- OpenCV OpenCV (opencv-python) reads BMP images into NumPy arrays. How to load and save BMP in Python, write 32-bit BMP with alpha, encode BMP in memory.
- Pillow Pillow is the standard Python imaging library. How to open and save BMP and DIB files, choose the bit depth, read the compression type, convert BMP to PNG.