我正在尝试在画布上查找像素是否为黑色
var check = function(player,keyPressed) {
//series of ifs to determine what pixel to check.
}
如果像素为假,我将需要返回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
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句