javascript - Uncaught TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The provided double value is non-finite -
i wrote code data canvas on 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 = []; (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"); (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 called every time mouse moved) , keep getting error: canvastest.js:17 uncaught typeerror: failed execute 'getimagedata' on 'canvasrenderingcontext2d': provided double value non-finite.
i have done searching around on stack overflow, google, , more , found nothing conclusive on error or how fix it.
thanks help!
you trying add value string array wothout casting:
checkx = x+checkpoints[i].split(",")[0]; checky = y+checkpoints[i].split(",")[1];
maybe should use:
checkx = x + parsefloat(checkpoints[i].split(",")[0]); checky = y + parsefloat(checkpoints[i].split(",")[1]);
Comments
Post a Comment