2

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 ?

2
  • What is imagedata? How are you setting it? Commented Oct 1, 2014 at 9:34
  • Just a simple ctx.getImageData. I edited myquestion Commented Oct 1, 2014 at 10:42

1 Answer 1

1

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];
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer, I will try it in my project when i get back to it. I keep you posted if it works !
It did not for me. Firstly the length of the array has to be W*H, because with var data_u32 = new Uint32Array(imageData.data.buffer); , data_u32.length equals imageData.data.length/4 equals W*H. then in your code you're refering to an unset n. With this respected Im still not getting the result s im expecting. (Im working with jsfeats' canny edge detector)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.