I wrote some code to get data from a canvas on a website:
var checkPoints = ["+0,+0","+10,+10","+10,+0","+0,+10","-10,-10","-10,+0","+0,-10","+20,+20","+20,+0","+0,+20","-20,-20","-20,+0","+0,-20","+30,+30","+30,+0","+0,+30","-30,-30","-30,+0","+0,-30","+40,+40","+40,+0","+0,+40","-40,-40","-40,+0","+0,-40","+40,+40","+40,+0","+0,+40","-40,-40","-40,+0","+0,-40"];
var changePoints = ["600,0","-100,400","-100,300","600,580","-100,1000","1000,300","0,0","600,0","-100,400","-100,300","600,580","-100,1000","1000,300","0,0","600,0","-100,400","-100,300","600,580","-100,1000","1000,300","0,0","600,0","-100,400","-100,300","600,580","-100,1000","1000,300","0,0","600,0","-100,400","-100,300","600,580","-100,1000","1000,300","0,0"];
var checkRGB = [];
var oldCheckRGB = [];
for (i=0; i<checkPoints.length; i++) {
checkRGB.push("");
oldCheckRGB.push("");
}
var mousePos = myCanvas.relMouseCoords(e);
x = mousePos.x;
y = mousePos.y;
c = myCanvas.getContext("2d");
for (i=0; i<checkPoints.length; i++) {
checkX = x+checkPoints[i].split(",")[0];
checkY = y+checkPoints[i].split(",")[1];
console.log("CheckX: "+checkX+", CheckY: "+checkY);
checkRGB[i] = c.getImageData(x+checkX, y+checkY, ID("myCanvas").width, ID("myCanvas").height).data;
if (checkRGB[i][0]-oldCheckRGB[i][0] > minimumColorChange || checkRGB[i][1]-oldCheckRGB[i][1] > minimumColorChange || checkRGB[i][2]-oldCheckRGB[i][2] > minimumColorChange) {
xm = changePoints[i].split(",")[0];
ym = changePoints[i].split(",")[1];
console.log("XM set: "+xm+", YM set: "+ym);
}
}
(This code is called every time the mouse is moved) And I keep getting the error: canvasTest.js:17 Uncaught TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The provided double value is non-finite.
I have done some searching around on stack overflow, google, and more and found nothing conclusive on this error or how to fix it.
Thanks for your help!
You are trying to add a value from the string array without any casting:
checkX = x+checkPoints[i].split(",")[0];
checkY = y+checkPoints[i].split(",")[1];
Maybe you should use:
checkX = x + parseFloat(checkPoints[i].split(",")[0]);
checkY = y + parseFloat(checkPoints[i].split(",")[1]);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments