4

I'm using npm:get-pixels which returns an ndarray and I'm having some trouble understanding how to correctly work this array.

Assuming pixels is the ndarray

console.log(pixels.get(800, 200, 0));
console.log(pixels.get(800, 200, 1));
console.log(pixels.get(800, 200, 2));

will print the RGB value of the pixel at coordinates [800,200] of the image.

Do I have to use three seperate .get() to achieve this?

Node Libray
get-pixels

Fletch
  • 450
  • 1
  • 4
  • 15

1 Answers1

5

In the end I used this

function getPixel(x, y, pixels) {
    var out = [];
    var pointer = pixels.offset + (pixels.stride[0] * x) + (pixels.stride[1] * y);

    for(var i=0; i<4; i++) {
        out.push(pixels.data[pointer + (pixels.stride[2] * i)]);
    }

    return out;
}
Fletch
  • 450
  • 1
  • 4
  • 15