Images and animations for the U8g2 library
U8g2 draws images with drawXBMP(), which uses the XBM format: rows of bytes where the leftmost pixel is in the lowest bit. That is the opposite of Adafruit's drawBitmap, which is why pasted arrays often look mirrored. This converter outputs correct XBM arrays, or smaller drawBox / drawLine code, with the right U8g2 constructor for your display.
U8g2 constructors used
| Display | Full buffer constructor |
|---|---|
| 0.96" SSD1306 128x64 | U8G2_SSD1306_128X64_NONAME_F_HW_I2C |
| 1.3" SH1106 128x64 | U8G2_SH1106_128X64_NONAME_F_HW_I2C |
| 0.91" SSD1306 128x32 | U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C |
| 1.5" SH1107 128x128 | U8G2_SH1107_128X128_F_HW_I2C |
| 1.5" SSD1327 128x128 | U8G2_SSD1327_WS_128X128_F_HW_I2C |
| 0.66" SSD1306 64x48 | U8G2_SSD1306_64X48_ER_F_HW_I2C |
On boards with little RAM, such as the Arduino Uno with a 128x128 screen, the converter switches to the page-buffer version (_2_) and a firstPage() / nextPage() loop.
Smaller than a bitmap: vector drawing code
A normal OLED bitmap stores every pixel: a full 128x64 screen is always 1,024 bytes, and an animation multiplies that by the number of frames. Most OLED graphics are outlines, icons and simple shapes, which take far less space as drawing commands. This converter can turn your bitmap into rectangles (fillRect / drawBox), rectangles plus 45° lines (drawLine) or run-length rows.
Auto mode compares every method with the plain bitmap, including the extra library code each one needs, and picks the smallest. Photos and dithered images usually stay as bitmaps. Every result is checked pixel-for-pixel against your original, so the screen shows exactly the same picture.
Supported OLED displays, boards and libraries
| Display | Driver chip | Library code |
|---|---|---|
| 0.96" 128x64 | SSD1306 | Adafruit SSD1306 or U8g2 |
| 1.3" 128x64 | SH1106 | Adafruit SH110X or U8g2 |
| 0.91" 128x32 | SSD1306 | Adafruit SSD1306 or U8g2 |
| 1.5" 128x128 | SH1107 / SSD1327 | Adafruit SH110X (SH1107) or U8g2 |
| 0.69" 96x16 | SSD1306 | Adafruit SSD1306 or U8g2 |
| 0.66" 64x48 (Wemos shield) | SSD1306 | U8g2 |
Boards: Arduino Uno, Nano, Mega 2560 and Nano Every, ESP32 (S2, S3, C3), ESP8266 (NodeMCU, Wemos D1), STM32 Blue Pill and Raspberry Pi Pico (RP2040). The generated sketch includes the I2C wiring for your board and stores images in flash (PROGMEM), so they don't use RAM.
Frequently asked questions
What is an XBM image and why does U8g2 use it?
XBM is a simple 1-bit image format stored as a C array. Each row is padded to whole bytes and the leftmost pixel is the lowest bit. U8g2 reads it from flash with drawXBMP(x, y, width, height, array).
Should I use the U8g2 full buffer or page buffer mode?
Full buffer (_F_) is simplest and fastest but needs width × height ÷ 8 bytes of RAM, 1,024 bytes for 128x64. Page mode (_1_ or _2_) uses only 128 or 256 bytes and redraws the picture in strips, which suits an Arduino Uno.
Can I convert Adafruit or image2cpp arrays to XBM?
Yes. Paste the arrays, choose the U8g2 library and the "Keep as bitmap" method. The converter detects the original format and writes XBM data for drawXBMP.
Does U8g2 work with SH1106 and SSD1327 displays?
Yes. U8g2 supports SSD1306, SH1106, SH1107, SSD1327 and many more controllers. The converter picks the matching constructor when you select your display.
Are my images uploaded to a server?
No. The converter runs entirely in your web browser. Your images, GIFs and code never leave your computer.