Home › Developer Tools › Image to C Array

Image to C Array

Convert a picture into a C byte array ready for an embedded display. Pick the screen size, choose monochrome with threshold and dithering, grayscale, RGB565 or RGB888, and see exactly what the display will show before you copy the code.

Last updated:

Converted preview
Advertisement
Advertisement

How to use the Image to C Array

  1. Drop an image, choose one, or paste it with Ctrl+V. A sample is loaded so you can try the settings first.
  2. Pick the display size from the presets or type a custom width and height, then choose how the image is scaled.
  3. Choose the color format your driver expects: monochrome for most OLEDs, RGB565 for color TFTs.
  4. Tune the result with the threshold, dithering, invert and byte layout while watching the preview.
  5. Copy the array or download the .h file and draw it with your display library.

Color formats and memory use

FormatBits per pixel128 × 64240 × 240Typical displays
Monochrome 1-bit11,024 B7,200 BSSD1306, SH1106, PCD8544 (Nokia 5110), e-paper
Grayscale 4-bit44,096 B28,800 BSSD1322, SSD1327 grayscale OLEDs
Grayscale 8-bit / RGB33288,192 B57,600 BSprites with 8-bit palettes, LVGL L8
RGB5651616,384 B115,200 BILI9341, ST7735, ST7789, GC9A01, SSD1351
RGB8882424,576 B172,800 BDesktop frame buffers, LED matrices, image processing

An Arduino Uno has 32 KB of flash, so a full-screen 128 × 64 monochrome image fits easily but a 240 × 240 RGB565 image (112.5 KB) needs a board such as an ESP32 or RP2040.

Drawing the array

// Adafruit SSD1306 / GFX: horizontal, MSB first
display.drawBitmap(0, 0, image, IMAGE_WIDTH, IMAGE_HEIGHT, SSD1306_WHITE);
display.display();

// u8g2: horizontal, LSB first (XBM)
u8g2.drawXBMP(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, image);

// TFT_eSPI: RGB565 as uint16_t words
tft.pushImage(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, image);

Tips for crisp results

  • Design at the final size. Scaling a large photo down to 128 × 64 loses detail; text and icons drawn at the display's exact resolution stay sharp.
  • Check the preview at zoom: it shows exactly the pixels that will be lit, including dithering patterns and the padding added when the width is not a multiple of 8.
  • Transparent PNGs are placed on black or white first; choose the one that matches your screen's background.
  • Colors look wrong on a TFT? If red and blue are swapped, the panel is in BGR mode; if colors look noisy, try the byte-swapped (big-endian) RGB565 option or your library's setSwapBytes().

Frequently asked questions

Which byte layout does my OLED library need?

Adafruit GFX drawBitmap() expects horizontal rows, most significant bit first, each row padded to a whole byte. u8g2 drawXBM() expects horizontal rows with the least significant bit first (XBM format). Writing straight into an SSD1306 or SH1106 frame buffer needs vertical pages: each byte is a column of 8 pixels with bit 0 at the top.

What is RGB565?

RGB565 packs a color into 16 bits: 5 bits of red, 6 of green and 5 of blue, computed as ((R & 0xF8) << 8) | ((G & 0xFC) << 3) | (B >> 3). It is the native format of most SPI TFT controllers such as the ILI9341, ST7735 and ST7789. Libraries like TFT_eSPI and Adafruit GFX's drawRGBBitmap() take uint16_t arrays; some DMA routines need the two bytes swapped (big-endian).

How big will the array be?

A monochrome image needs width × height ÷ 8 bytes, so a 128 × 64 OLED screen is 1,024 bytes. 4-bit grayscale needs half a byte per pixel, RGB332 and 8-bit grayscale one byte, RGB565 two bytes and RGB888 three bytes per pixel, so a 240 × 240 RGB565 image is 115,200 bytes.

When should I use dithering?

Use dithering for photos, gradients and shaded logos on 1-bit screens: it simulates gray levels with patterns of dots. Floyd–Steinberg gives the smoothest result, Atkinson keeps more contrast, and ordered (Bayer) dithering gives a regular pattern that looks good on small displays. For text, icons and line art, plain thresholding is sharper.

What does the threshold do?

Each pixel's brightness is calculated as 0.299 R + 0.587 G + 0.114 B (0 to 255). Pixels at or above the threshold become 1 (lit) and darker pixels become 0. Lower the threshold to light up more pixels, raise it for fewer, or tick Invert to swap them.

Do I need PROGMEM?

On AVR boards such as the Arduino Uno or Nano, yes: without PROGMEM a constant array is copied into the 2 KB of RAM at startup. Libraries like Adafruit GFX read PROGMEM bitmaps with pgm_read_byte(). On ESP32, ESP8266, RP2040 and ARM boards const data stays in flash anyway, and PROGMEM is defined as empty for compatibility.

Is my image uploaded?

No. The image is decoded, scaled and converted with the canvas API in your browser, and the code is generated on your device.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

File to C ArrayConvert any file into a C or C++ byte array header, like xxd -i, with const and PROGMEM options.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Image Dithering ToolDither photos with Floyd-Steinberg, Atkinson or Bayer in 1-bit, Game Boy, CGA and retro palettes.Pixel Art MakerDraw pixel art on an 8 to 64 px grid with palettes, fill and mirror, then export PNG or SVG.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON to Go StructTurn JSON into Go structs with inferred types, nested structs and json tags.ES6 to ES5 ConverterTranspile modern JavaScript (ES2015+) to ES5 with Babel: targets, module format and loose mode.JavaScript Object to JSONTurn JS object literals and Python dicts into valid JSON: quotes keys, fixes commas and values.JSON Graph VisualizerSee JSON as an interactive node graph with zoom, collapse and search; export PNG or SVG.KML ViewerOpen KML and KMZ files on an interactive map: placemarks, paths, polygons, folders, export.MySQL to PostgreSQL ConverterConvert MySQL dumps and CREATE TABLE statements to PostgreSQL: types, AUTO_INCREMENT, ENUMs, quotes.Text to CSV ConverterTurn space-aligned, fixed-width, pipe or tab separated text into clean CSV with a live preview.VCF File ViewerOpen vCard .vcf files as contact cards with photos, search and duplicate check, export CSV.XML ViewerBrowse XML as a collapsible tree with search, XPath of any node, attributes and big-file support.JSON to Python ClassGenerate Python dataclasses, Pydantic models or TypedDicts with type hints from JSON.JSON to C# ClassConvert JSON to C# classes or records with System.Text.Json or Newtonsoft attributes.JSON SorterSort JSON keys A-Z recursively, sort arrays by value or by a key, then pretty-print or minify.JSON to HTML TableConvert a JSON array of objects into clean HTML table code with CSS styles and a live preview.CSV to SQL ConverterConvert CSV to SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.IPv4 to IPv6 ConverterConvert IPv4 to IPv4-mapped, 6to4 and NAT64 IPv6, extract IPv4 from IPv6, and get int/hex/binary.cURL to Code ConverterConvert curl commands to JavaScript fetch, Axios, Python requests, Node.js, PHP and Go code.Code to ImageTurn code into a beautiful syntax-highlighted PNG with themes, window frame and background.Excel to JSON ConverterConvert Excel sheets (XLSX, XLS, ODS) to JSON with header row, type and shape options.CSV to Excel ConverterConvert CSV files to a real .xlsx workbook with typed numbers and dates, one sheet per file.CSV SplitterSplit a large CSV into smaller files by row count, file count or column value, header kept.CSV MergerCombine many CSV files into one, matching columns by name, with dedupe and a source column.VCF to CSV ConverterConvert vCard (.vcf) contacts to CSV for Google or Outlook, or turn a CSV back into a VCF.Calendar Event (.ics) GeneratorCreate an .ics calendar invite with time zone, reminders and repeats + Google/Outlook links.CSV Column ExtractorPick, reorder and rename CSV columns, filter rows by value, and export a new CSV or JSON.CSV Diff CheckerCompare two CSV files by key column and see added, removed and changed rows cell by cell.CSV Duplicate Row RemoverRemove duplicate rows from a CSV by all or selected columns and download the cleaned file.CSV to HTML TableTurn CSV into clean HTML table code with a live preview, styling options and one-click copy.CSV to Markdown TableConvert CSV to a neatly aligned GitHub Markdown table with column alignment and live preview.CSV TransposeSwap rows and columns of CSV, TSV or pasted spreadsheet data, with delimiter auto-detect.Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.ENV to JSON ConverterConvert .env files to JSON or YAML and JSON back to .env, with quotes and multiline values.
See all 129 Data & File Format Converters →