Home

U8g2 Image Converter (XBM)

PNG, JPG or GIF to U8g2 drawXBMP arrays and sketches for Arduino & ESP32 OLEDs

Guide
ESP32 Flash Check

Rectangles: 3486 B · Rects + lines: 2906 B · Run-length: 3030 B · Bitmap: 4096 B

Uses 0.2% of the ESP32's 1.25 MB app space flash. Sizes are image data plus any extra drawing code each method needs (measured on Arduino Uno; the display library itself is not counted). ✓ Output checked pixel-for-pixel against your bitmap.

As bitmap 4,096 B 8 × 64x64
Rects + lines (auto) 2,906 B 308 rects + 292 lines · incl. ~470 B code
Memory saved
1,190 B 29.1%

Input Bitmap Code

ESP32

Arduino code (.ino .h .c .cpp .xbm), images (PNG JPG BMP WebP) or an animated GIF. Select several images to make an animation, or drop files here.

Image size (px)
×
Position on screen
X Y

OLED Live Preview

0 Frames
0.96" 128x64 SSD1306
FPS: 15 I2C 0x3C
Playback
15 FPS
Frames Frame 0 / 0
No frames yet

Arduino Code

// Paste bitmap code and press Convert.

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

DisplayFull buffer constructor
0.96" SSD1306 128x64U8G2_SSD1306_128X64_NONAME_F_HW_I2C
1.3" SH1106 128x64U8G2_SH1106_128X64_NONAME_F_HW_I2C
0.91" SSD1306 128x32U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C
1.5" SH1107 128x128U8G2_SH1107_128X128_F_HW_I2C
1.5" SSD1327 128x128U8G2_SSD1327_WS_128X128_F_HW_I2C
0.66" SSD1306 64x48U8G2_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

DisplayDriver chipLibrary code
0.96" 128x64SSD1306Adafruit SSD1306 or U8g2
1.3" 128x64SH1106Adafruit SH110X or U8g2
0.91" 128x32SSD1306Adafruit SSD1306 or U8g2
1.5" 128x128SH1107 / SSD1327Adafruit SH110X (SH1107) or U8g2
0.69" 96x16SSD1306Adafruit SSD1306 or U8g2
0.66" 64x48 (Wemos shield)SSD1306U8g2

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.

More OLED converters