0

I have a onload function as follows:

  canvas = document.getElementById('canvas')
  context = canvas.getContext('2d');
  var imageData;
  var buffer;
  var binary;
  var uint = [];
  img.onload = function () {
  canvas.getContext('2d').drawImage(img, 0, 0, canvas.width, canvas.height);   
  imageData = context.getImageData(0, 0, canvas.width, canvas.height);
  buffer = imageData.data.buffer;
  binary = new Uint8Array(buffer);      
  for (var i = 0; i < binary.length; i++) {
          uint.push(binary[i]);
      }
  }

Now my uint is array with all the values of binary.

I am declaring function that uses this uint array as:

var request = new somefunction({
    image : {
      height: canvas.height,
      data: uint}
  });

When i check my chrome console uint is retaining all the values that i declared in onload function. But when i am trying to access image.data it is a blank array.

What am i doing wrong here?

Dumb_Shock
  • 1,050
  • 1
  • 13
  • 23

0 Answers0