Bitmap to Byte Array Converter
Convert bitmap images to C/Arduino/Python byte arrays for embedded displays. Supports threshold, dithering, MSB/LSB, and multiple output formats.
About
Embedded display controllers like SSD1306, ST7735, and ILI9341 consume image data as packed byte arrays stored in program memory. A single misaligned bit order or wrong scan direction produces garbled output on screen. This tool decodes any raster image, applies configurable luminance thresholding (T โ [0, 255]) using the BT.601 standard (L = 0.299R + 0.587G + 0.114B), and packs the resulting 1-bit pixels into bytes with precise control over bit order and scan direction. Optional Floyd-Steinberg dithering preserves perceptual detail that hard thresholding destroys.
The converter targets real hardware constraints. Arduino PROGMEM arrays must use const qualifiers and correct data types to avoid RAM exhaustion on ATmega328P chips with only 2 KB SRAM. Output format errors cause silent failures: the display shows noise, not an error message. This tool validates dimensions, calculates exact byte counts (W ร H รท 8), and generates copy-ready code. Note: images exceeding 128ร64 pixels may exceed flash capacity on 8-bit microcontrollers.
Formulas
Each pixel is first converted to luminance using the ITU-R BT.601 luma coefficients:
The luminance value is compared against a user-defined threshold T to produce a binary pixel P:
When Floyd-Steinberg dithering is enabled, the quantization error e is distributed to neighboring pixels:
pixel(x+1, y) += e โ 716
pixel(xโ1, y+1) += e โ 316
pixel(x, y+1) += e โ 516
pixel(x+1, y+1) += e โ 116
Binary pixels are packed into bytes. For horizontal MSB-first packing, byte index B and bit position b for pixel at column x, row y in an image of width W:
b = 7 โ (x mod 8)
Total byte count for a 1-bit monochrome image:
Where R, G, B are red, green, blue channel values (0 - 255); L is luminance; T is threshold; Q is quantized output (0 or 255); W is image width in pixels; H is image height in pixels; N is total bytes in the output array.
Reference Data
| Display Controller | Resolution | Color Depth | Interface | Byte Order | Scan Direction | Typical MCU | Flash Usage |
|---|---|---|---|---|---|---|---|
| SSD1306 | 128ร64 | 1-bit mono | IยฒC / SPI | LSB first (vertical) | Vertical (page mode) | ATmega328P | 1024 bytes |
| SSD1309 | 128ร64 | 1-bit mono | IยฒC / SPI | LSB first | Vertical | ESP32 | 1024 bytes |
| SH1106 | 132ร64 | 1-bit mono | IยฒC / SPI | LSB first | Vertical | ATmega328P | 1056 bytes |
| ST7565 | 128ร64 | 1-bit mono | SPI | MSB first | Horizontal | ATmega2560 | 1024 bytes |
| Nokia 5110 (PCD8544) | 84ร48 | 1-bit mono | SPI | MSB first | Horizontal | ATmega328P | 504 bytes |
| ST7735 | 128ร160 | 16-bit RGB565 | SPI | MSB first | Horizontal | ESP32 | 40960 bytes |
| ILI9341 | 240ร320 | 16-bit RGB565 | SPI | MSB first | Horizontal | ESP32 | 153600 bytes |
| MAX7219 | 8ร8 (chainable) | 1-bit mono | SPI | MSB first | Horizontal | ATmega328P | 8 bytes |
| HT16K33 | 16ร8 | 1-bit mono | IยฒC | LSB first | Horizontal | ATmega328P | 16 bytes |
| EPD (e-Paper) 2.9โณ | 296ร128 | 1-bit mono | SPI | MSB first | Horizontal | ESP32 | 4736 bytes |
| EPD (e-Paper) 4.2โณ | 400ร300 | 1-bit mono | SPI | MSB first | Horizontal | ESP32 | 15000 bytes |
| UC1701 | 128ร64 | 1-bit mono | SPI | MSB first | Vertical | STM32 | 1024 bytes |
| SSD1351 | 128ร128 | 16-bit RGB565 | SPI | MSB first | Horizontal | ESP32 | 32768 bytes |