If you've ever tried to put a custom logo or image on an Arduino OLED display, you've probably run into this question: "How do I
turn my PNG file into something Arduino understands?" The answer is converting your image to a byte array, a long
list of numbers that represents your image pixel by pixel. I remember being totally baffled by this the first time. The code
examples showed these huge blocks of hex numbers like 0xFF, 0x81, 0x42... and I had no clue where they came from.
Your Arduino can't read PNG, JPG or GIF files directly. It doesn't have a file system or an image decoder. Nothing. Instead, you've got to turn the image into a byte array stored in PROGMEM (flash memory) that your code can reference. Each byte in that array controls 8 pixels on your display. This guide shows you exactly how that conversion works, how the popular image2cpp tool fits in, and when you'll want an alternative that handles animations too.
By the end, you'll know not just how to convert images, but why it works the way it does. That'll save you when things go wrong, like when your image shows up upside down, inverted, or scrambled (all mistakes I've made and will help you avoid).
What exactly is an "image to byte array" conversion?
Let me explain it the simplest way I can. Once it clicks, the rest makes sense.
Step 1: Your image becomes black and white
OLED displays like the SSD1306 are monochrome, so each pixel is either ON (lit) or OFF (dark). There's no gray and no color. The first thing that happens is your colorful image gets turned into pure black and white. A "threshold" value decides which pixels turn white and which turn black. Anything brighter than the threshold turns on. Anything darker turns off.
Step 2: Pixels get packed into bytes
Now here's the clever part. You don't store each pixel separately, since that's wasteful. You pack 8 pixels into a single byte. A byte is 8 bits, and each bit is one pixel: 1 means "on" and 0 means "off." So the byte 0b11110000 (or 0xF0
in hex) means "first four pixels on, last four pixels off."
A 128×64 pixel display has 8,192 pixels total. Pack them 8 per byte and you'll get exactly 1,024 bytes per image. That's why people call a full-screen 128×64 frame "1KB." Now you know where it comes from.
Step 3: The bytes become a C++ array
Finally, you write all those bytes out as a C++ array, like this:
const unsigned char myLogo[] PROGMEM = {
0xFF, 0x81, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42,
// ... hundreds more bytes ...
};
The PROGMEM keyword tells Arduino to keep this array in flash memory, where there's lots of room, instead of RAM, where there's barely any. Then you display it in your code with one line:
display.drawBitmap(0, 0, myLogo, 128, 64, WHITE);
That's the whole trick. Image → black & white → packed bytes → C++ array → displayed with drawBitmap. It's simple once you see it laid out.
image2cpp: the classic tool for single images
To convert one image to a byte array, image2cpp (created by javl, hugely popular on GitHub) is the tool everyone reaches for. Honestly, it's excellent at what it does. I've used it plenty for static logos and icons.
How to use image2cpp
- Upload your image: Drag a PNG, JPG or BMP into the tool
- Set the canvas size: Match your display, which is usually 128×64
- Adjust the threshold: Slide it until your image looks right in the preview. It controls which pixels you get as black vs white
- Pick the output format: Choose "Arduino code, single bitmap" if you're using Adafruit GFX
- Copy the generated array: Paste it into your sketch and you're done
For a logo on your project's splash screen, or a single weather icon, image2cpp is perfect. It's quick and free, with no nonsense.
Common image2cpp gotchas (learn from my mistakes)
- Image appears inverted: Toggle the "Invert image colors" checkbox. Sometimes your background and foreground swap places.
- Wrong orientation: Make sure the "Draw mode" matches how your library reads bitmaps. Horizontal vs vertical byte ordering matters a lot, and it's the usual culprit.
- Blurry or muddy result: Your source image had too many midtones. Boost the contrast in an image editor first, or turn on dithering.
- Array too big: You probably didn't resize the image to your display's dimensions before converting.
When you need more than image2cpp (the animation problem)
Here's where image2cpp hits its limit. It's built for single images, and that's all. But what if you want an animation? Say you've got a 15-frame loading spinner, or an animated GIF you want to convert. With image2cpp, you'd have to:
- Split your GIF into 15 separate PNG files by hand
- Convert each one individually through image2cpp (15 times!)
- Copy-paste 15 arrays into your sketch
- Write the frame-cycling logic yourself
- Add timing code for the right FPS
- Debug it all when one array has the wrong size
I did this once for a 20-frame animation. It took me over an hour, and I made two copy-paste errors that caused glitches. Never again. That's what pushed me to build a better tool.
What an animation-focused alternative gives you
- Multi-frame conversion, so you can import a whole GIF or PNG sequence at once and get every frame converted automatically
- Timeline with FPS control, so you can adjust playback speed visually and preview before you export
- Multiple library targets, so you can export for Adafruit SSD1306, U8g2 or MicroPython framebuf
- Automatic SH1106 offset, so you don't adjust coordinates by hand for SH1106 displays
- Complete project export, so you get the full working sketch (arrays + playback loop), not just isolated arrays
- Built-in dithering, using Floyd-Steinberg, so your photos and gradients convert better
Using the OLED Animation Maker as an image2cpp alternative
Here's how you convert images, single or animated, with the free OLED animation maker. It handles both static images and full animations:
- Import tab: Drop in your PNG, JPG or GIF. Every frame converts to byte arrays on its own, so you're not doing it by hand.
- Adjust threshold and dithering: Fine-tune how your image turns black and white. You'll see a live preview.
- Draw tab (optional): Use the built-in pixel editor if you'd rather design from scratch or touch up your imported frames.
- Animate tab: Arrange your frames on a timeline, set your FPS, and preview the motion.
- Get the Code: Export the complete sketch, with byte arrays plus the playback loop, ready for you to upload.
You get the same core output as image2cpp (PROGMEM byte arrays), but the animation workflow is built in and you choose the library. For single images, it works just like image2cpp. For animations, it saves you that hour of tedious manual work.
Convert one image right now
The free Image to Byte Array converter works like image2cpp: drop in a PNG or JPG, set the threshold and dithering, and copy a PROGMEM array for Adafruit GFX, an XBM array for U8g2, or a MicroPython bytearray.
Open the converter →Image → byte array + animation loop
Free online, SSD1306, SH1106, ESP32, Pico. Want your pixels to assemble into a name or logo? Try Assemble Studio.
Open Tool →Frequently asked questions
What is the difference between a byte array and a bitmap?
They're basically the same thing here. A "bitmap" is an image made of pixels, and a "byte array" is how you store that bitmap in code, as a list of bytes where each bit is one pixel. When people say "convert image to byte array," they mean turning a picture into this code-friendly format.
Why use PROGMEM for image arrays?
Arduino has very little RAM, only 2KB on an Uno. A single 128×64 image needs 1KB, which is half your RAM. PROGMEM keeps the array in flash memory instead (32KB on Uno), so you've still got RAM for your actual program. That's why it matters. Always use PROGMEM for image data.
My image shows up inverted (black and white swapped). How do I fix it?
This is super common. Either toggle the "invert" option in your conversion tool, or change the color parameter in drawBitmap from WHITE to BLACK (or the other way round). It's a one-click fix once you know where to look.
Can I convert a color image, or does it have to be black and white?
You can start with any color image. The tool turns it black and white using a threshold, and you can add dithering for better results. Just remember your display is monochrome, so high-contrast images work best.
What's dithering and should I use it?
Dithering fakes shades of gray with patterns of black and white dots, the way newspapers print photos. Use it for photos and gradients when you'd like to keep the detail. Skip it for logos, text and simple graphics, where you'll want clean, solid shapes.
Why is a 128×64 image always 1024 bytes?
128 times 64 is 8192 pixels. The OLED stores one bit per pixel, and a byte holds 8 bits, so 8192 / 8 = 1024 bytes. A smaller icon is smaller: an 8×8 glyph is 8 bytes if you pack eight vertical pixels into each byte.
My logo is mirrored or sliced into horizontal bars. What setting is wrong?
Adafruit GFX drawBitmap reads horizontal bytes: each byte is eight pixels across a row, and the leftmost pixel is the high bit. A vertical page-mode array (one byte per column) paints stripes. In image2cpp, pick the horizontal 1-bit mode that matches Adafruit GFX, then convert again.
Can I store the array in RAM instead of PROGMEM?
On an Uno, no. The frame is 1024 bytes and you've only got 2048 of SRAM. Leave the array in PROGMEM and let drawBitmap read it with the library's flash helpers. If you copy the whole frame into a RAM buffer, your sketch will reboot as soon as the image draws.
Worked example: pack an 8×8 mark, then a full frame
You'll trust a full-screen logo more once you've packed one tiny glyph by hand. Adafruit GFX drawBitmap stores your picture in horizontal bytes. Each byte is eight pixels in a row, and the leftmost pixel is the most significant bit. An 8×8 mark is one byte per row. That's eight bytes, not 64.
A hollow 8×8 box makes a handy check. The top and bottom rows are every pixel on: 0xFF. Each middle row is only the left and right pixels on, which is 10000001 binary, or 0x81. If that box draws as vertical stripes, your array was built in column-page order and the library's reading it as rows.
// Horizontal, MSB = left pixel. An 8x8 outline.
const unsigned char mark[] PROGMEM = {
0xFF,
0x81, 0x81, 0x81, 0x81, 0x81, 0x81,
0xFF
};
display.drawBitmap(60, 28, mark, 8, 8, SSD1306_WHITE);
That call draws an 8×8 bitmap whose top-left is (60, 28), so it sits near the middle of a 128×64 panel and won't clip. Scale the same packing up. A row of 128 pixels is 16 bytes, times 64 rows, which is 1024 bytes. image2cpp and the animation maker both give you that length when the canvas is 128×64 and the output is a single Adafruit bitmap. If the array you pasted is 512 bytes, the source was 128×32 or half the rows got dropped. If it's 1056 bytes, someone built a 132-column SH1106 buffer (132 × 64 / 8). A normal SSD1306 frame shouldn't be 1056. Those extra columns are the SH1106 offset story, not a denser image.
Check it on your hardware: Uno SDA A4, SCL A5, begin(..., 0x3C). ESP32 uses GPIO 21 and GPIO 22. ESP8266 NodeMCU uses D2 and D1. Draw the 8×8 mark first. If those eight bytes look like noise, your byte order is wrong, and a 1024-byte logo will look like noise too. Fix the mode, then convert your real PNG.
For a photograph, raise the contrast before the threshold, or turn dithering on. For a wordmark, leave dithering off so the edges stay solid. Invert only if your panel shows a white rectangle with a black logo and you wanted the opposite. PROGMEM stays on the array either way.
Troubleshooting a scrambled byte array
- Stripes every eight pixels. You drew a column-packed (vertical) array with Adafruit's horizontal
drawBitmap. Re-export it as horizontal 1-bit, with the leftmost pixel in the high bit. It's a two-minute fix. - Image upside down. Blame the tool's "flip" or a library rotation setting. Don't hand-reverse 1024 hex values. You don't need to. Toggle the option and convert once.
- Right side clipped, left side has a two-pixel gap. Your panel is SH1106 and the bitmap starts at column 0 of a 132-wide controller. Export with SH1106 selected, or pass x = 2 only if your driver doesn't already offset.
- Sketch uploads, then the board resets on drawBitmap. Your array is in RAM. Add PROGMEM, and don't
memcpythe frame into a 1024-byte SRAM buffer on an Uno. - Logo is tiny in the corner. Your width and height arguments still say 8, 8 from the test glyph. A full frame needs
drawBitmap(0, 0, logo, 128, 64, SSD1306_WHITE). - Colors swapped. Invert in the converter, or swap
SSD1306_WHITEandSSD1306_BLACKon a cleared black background. Do one of those, not both, or you'll invert twice and land right back where you started.
Related guides you might like
- Make beautiful OLED animations with AI pixel art and lyrics
- Assemble Studio, name & logo animations
- GIF to OLED Arduino
- SSD1306 animation guide
- Arduino OLED display tutorial
Free tools: OLED Animation Maker for your SSD1306 and SH1106 animations, Assemble Studio for your name and logo animations, the Shadow Box Lamp Generator for your 3D-printed shadow lamps, Text to STL for your 3D-printed names and keychains, and 3MF to Web to show your 3D prints on any website. New: the Image to Byte Array converter, the OLED Robot Eyes generator and the Lithophane Maker. See all tools.