首页 > 代码库 > -_-#【Canvas】转成黑白

-_-#【Canvas】转成黑白

技术分享

function drawInBlackAndWhite() {   var imagedata = http://www.mamicode.com/context.getImageData(0, 0, canvas.width, canvas.height)   var data =http://www.mamicode.com/ imagedata.data      for (var i = 0, l = data.length - 4; i < l; i+=4) {      var average = (data[i] + data[i+1] + data[i+2]) / 3      data[i]   =      data[i+1] =      data[i+2] = average   }   context.putImageData(imagedata, 0, 0)}

 

-_-#【Canvas】转成黑白