Convert a PNG to a Byte Array
Embed an image directly in source so your binary has no external asset to find at runtime. Drop a PNG, pick your language, and copy out a ready-to-paste array of the file's exact bytes. Nothing is uploaded — the file is read locally.
Drop a PNG here
One file at a time · any file type works
These are the file's bytes, not the pixels
Worth being precise about, because it's the usual source of confusion. What you get is the
compressed PNG file byte for byte — starting with the 89 50 4E 47
signature. Feed it to stbi_load_from_memory, image::load_from_memory,
PIL.Image.open(BytesIO(...)) or a Blob and you get your image back
identically.
What you do not get is raw RGB565 or RGBA framebuffer data. If you're driving a small TFT or e-paper display that wants uncompressed pixels, you need a converter for that panel's specific format — most embedded graphics libraries ship one. Decoding PNG on an MCU also needs a decoder in flash and a chunk of RAM, which is often why people want raw pixels in the first place.
Keeping the array small
Every byte becomes about six characters of source (0x89, ), so a 100 KB PNG
becomes roughly 600 KB of code. Compilers cope, code review does not. Shrink the image
before you embed it: Resize to the size you actually display,
Reduce colors for icons and UI art, and
Remove metadata to strip colour profiles and timestamps that
can easily account for a third of a small file.
FAQ
Which format should I choose for Arduino or ESP32?
C / C++. On AVR you'll usually also want PROGMEM on the declaration so the array lives in flash rather than RAM — add it after pasting.
Where does the variable name come from?
The filename, with the extension dropped and anything that isn't a letter or digit turned into an underscore. Rust uses the upper-case form to match the static-naming convention.
Can I do this with a JPG, WebP or any other file?
Yes. The file is read as raw bytes, so the type is irrelevant — any file works, image or not.
Wouldn't Base64 be more compact?
In source, yes — about a third the characters. Use PNG to Base64 for that. Byte arrays win when the target has no Base64 decoder, or when you want the data in flash with zero runtime decoding.
Why only one file at a time?
The output is a single named declaration. Multiple files would need multiple names and would just make the textarea unreadable — run them one after another.