我试图在画布上找出一个像素是否是黑色的
var check = function(player,keyPressed) {
//series of ifs to determine what pixel to check.
}
如果像素为false,我需要返回true或false,我尝试了getImageData,但是我无法弄清楚如何正确使用它。
我试图在画布上找出一个像素是否是黑色的
var check = function(player,keyPressed) {
//series of ifs to determine what pixel to check.
}
如果像素为false,我需要返回true或false,我尝试了getImageData,但是我无法弄清楚如何正确使用它。
var canvas= document.getElementById('myCanv');
var pixelData = canvas.getContext('2d').getImageData(event.clientX, event.clientY, 1, 1).data;
<canvas id="myCanv"></canvas>
接着:
function isBlack(dataPixel){
if(dataPixel[0]==dataPixel[1] && dataPixel[1]==dataPixel[2] && dataPixel[2]===0 ){
return true
}
}
dataPixel[0]+dataPixel[1]+dataPixel[2]==0
? - Tomáš ZatodataPixel [0] + dataPixel [1] + dataPixel [2] + dataPixel [3] == 0
- markE