Search code examples
javascriptnode.jshtml5-canvasv8

Create an empty PixelArray with V8 / node.js


I'd like to be able to make an empty PixelArray to compare with output from node-canvas from within JavaScript.

For example:

var cleanData = new PixelArray ( 20 );

Is this possible? Am I on the wrong version of Node.js? (0.8.3)


Solution

  • Uint8ClampedArray works.

    var cleanData = new Uint8ClampedArray( width * height * 4 );
    

    Some background:

    http://www.khronos.org/registry/typedarray/specs/latest/#7.1  Uint8ClampedArray is defined in order to replace CanvasPixelArray. It behaves identically to the other typed array views, except that the setters and constructor use clamping [WEBIDL] rather than modulo arithmetic when converting incoming number values.