Skip to content

Using with framebuffer devices

Zach Bjornson edited this page May 30, 2018 · 2 revisions

Starting with version 2.x, you can use node-canvas to write to framebuffer devices, such as the Adafruit PiTFT:

const {createCanvas} = require("canvas");
const canvas = createCanvas(480, 320, {pixelFormat: "RGB16_565"}); // important: RGB16_565

// Draw to your canvas:
const ctx = canvas.getContext("2d");
ctx.font = "30px impact";
ctx.fillText("Hello!", 50, 100);

// Write to the framebuffer device:
const fs = require("fs");
const fb = fs.openSync("/dev/fb1", "w"); // where /dev/fb1 is the path to your fb device
const buff = canvas.toBuffer("raw");
fs.writeSync(fb, buff, 0, buff.byteLength, 0);
Clone this wiki locally