RGB565 Color Converter
Convert a HEX or RGB color to 16 bit RGB565 and decode an RGB565 value back. See side by side what the display will actually print, and copy the Arduino code straight out. For ST7735, ST7789, ILI9341, ILI9488 and GC9A01 panels.
Paste several HEX colors (one per line or comma separated) and get them back as a single C array.
What is RGB565?
RGB565 is a color format that packs a color into 16 bits: 5 bits red, 6 bits green, 5 bits blue. Green gets the extra bit because the human eye resolves green differences best. The result is 65,536 colors in half the memory of 24 bit RGB888. Almost every small TFT driver, including the ST7735, ST7789, ILI9341, ILI9488 and GC9A01, uses it, because a microcontroller does not have the RAM for a full color framebuffer.
Bit layout
The top 5 bits of the 16 bit value are red, the middle 6 are green and the bottom 5 are blue:
bit 15 14 13 12 11 | 10 9 8 7 6 5 | 4 3 2 1 0
R R R R R | G G G G G G | B B B B B
uint16_t c = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);Common colors
| Color | HEX | RGB565 | Decimal |
|---|---|---|---|
| Black | #000000 | 0x0000 | 0 |
| White | #FFFFFF | 0xFFFF | 65535 |
| Red | #FF0000 | 0xF800 | 63488 |
| Green | #00FF00 | 0x07E0 | 2016 |
| Blue | #0000FF | 0x001F | 31 |
| Yellow | #FFFF00 | 0xFFE0 | 65504 |
| Cyan | #00FFFF | 0x07FF | 2047 |
| Magenta | #FF00FF | 0xF81F | 63519 |
RGB565 or RGB888?
The difference is memory. A 320x240 image is 230,400 bytes in RGB888 and 153,600 bytes in RGB565. Given that an Arduino Uno has 32 KB of flash in total, neither fits there; on an ESP32 RGB565 is comfortable while RGB888 is a squeeze. On a small panel there is no visible quality difference either, which is why RGB565 wins in practice almost every time.
Frequently Asked Questions
Why does my color look slightly different on the display?
RGB565 throws away the low bits of every channel. Red and blue can be off by up to 8 steps, green by up to 4. The two swatches above show exactly that: the left one is the color you picked, the right one is what the panel prints. Pastels and soft grey gradients show it most.
My colors come out inverted, what should I do?
That is a byte order problem. With TFT_eSPI, add or remove tft.setSwapBytes(true). Red and blue swapping usually means the panel is in BGR mode instead, so check the driver configuration too.
Should I use color565() or a constant?
tft.color565(r, g, b) reads well but computes on every call. If the color is fixed, writing the precomputed 0x... value as a #define is faster and smaller. This tool gives you both.
I want to convert a whole image, not one color
Use image2cpp instead. Pick the RGB565 output mode and it produces an array you can feed straight into drawRGBBitmap() or pushImage().
Is any of my data sent anywhere?
No. All conversion happens in your browser. Nothing is sent to a server and nothing is stored.