A handy tool for converting PNG images into RGB565 encoded uint16_t image buffers for use on embedded electronics (such as ST7789 / ILI9341 displays). It ouputs header files containing compressed RGB565 buffer data that can be drawn to a framebuffer (which is a fairly well supported practice for most displays). Out of the box this script is configured for displays with a resolution of 240x240.
This tool is built with Node.js, so you'll need a modern version of that installed. Clone the repo and run npm i
from the command line in the directory you've cloned to and you shoulld be good to go.
Place your image(s) into the img
directory run the script with the filename (without the extension) as the first parameter. It will then export the header file into the output
directory.
node index example
/img/example.png
➜/output/example.h
Simply import the header file into your project, include it at the top of your sketch and use the draw
function it exposes to write the data to your frame buffer. Here is a example without any of the actual screen initialisation stuff:
#include "output/example.h"
// Create a buffer, e.g.
uint16_t buffer[240*240];
void setup() {
// Call the draw function from our header, e.g.
img_example.draw(buffer);
}
- I am working on a version where you can specify clipping rects for when you only need to draw part of your image to part of the buffer / screen.
- Transparency and alpha blending
- Some unit tests etc.