arlg
arlg

Reputation: 1138

Array buffer IE10 - Typed array constructor argument is invalid

Im using Javascript canvas to change pixels on an image. At some point I need the array buffer to work with the jsfeat.js library.

IE10 tells me that "Typed array constructor argument is invalid" at this line :

var imageData = ctx.getImageData(0, 0, W, H);
var data_u32 = new Uint32Array(imagedata.data.buffer);

When I console.log imagedata.data.buffer, it gives me "undefined" in IE10. In Chrome I have " ArrayBuffer {}".

If i pass the data directly the effect is not working.

How can i fix this ?

Upvotes: 2

Views: 3094

Answers (1)

markE
markE

Reputation: 105035

IE10's .getImageData used a CanvasPixelArray rather than the newer Uint32Array.

(Uint32Array was available to IE10, but it wasn't implemented in canvas)

The CanvasPixelArray.data has no .buffer property--that's the cause of your error warning.

Example code to "manually" load imageData into your data_u32.

var imageData = ctx.getImageData(0, 0, W, H);

// init the array by size
var data_u32 = new Uint32Array(W*H*4);

// fill the array "manually"
var data=imageData.data;
for(var i=0;i<data.length;i++){
    data_u32[n]=data[n];
}

Upvotes: 1

Related Questions