load graphicsbuffer from sd card

Posted on
  • I would like to load a binary image from sd directly to a graphicsbuffer.
    The only way, it worked for me is this:

    var gr = Graphics.createArrayBuffer(64,32,4,{inte­rleavex:true});  //this is a 64x32 LED matrix
    fs = require("fs");
    var x = E.toUint8Array(fs.readFile("myFile.bin")­); //myFile.bin is binary file holding 1024 bytes
    for(var i = 0; i < 1024; i++) gr.buffer[i] = x[i];

    Using a temporary array and copy value by value in a loop looks strange to me.
    And it takes a lot of CPU power to copy.
    But all I tried to assign Uint8Array directly to graphics buffer, failed.
    Failed in the way, that loaded image was not shown.

    I'm pretty sure, there is a way to do better, but I don't find it.

  • I think it might be because g.buffer is a ArrayBuffer, not a Uint8Array.

    What about:

    fs = require("fs");
    (new Uint8Array(gr.buffer)).set(fs.readFile("­myFile.bin"));
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

load graphicsbuffer from sd card

Posted by Avatar for JumJum @JumJum