问答详情
源自:4-3 Canvas 更复杂的滤镜效果

灰色滤镜的问题

请问我这个灰色滤镜为什么无效

function greyEffect(){

var ImageData = contexta.getImageData(0,0,canvasa.width,canvasa.height)

var pixelData = ImageData.data

 

for(var i=0; i< canvasb.width * canvasb.height; i++){

var r = pixelData[i*4+0]

var g = pixelData[i*4+1]

var a = pixelData[i*4+2]

var grey = r*0.3 + g*0.59 + b*0.11

pixelData[i*4+0] = grey

pixelData[i*4+1] = grey

pixelData[i*4+2] = grey

}

contextb.putImageData(ImageData,0,0,0,0,canvasb.width,canvasb.height)

}


提问者:qq_快乐小2B_0 2017-05-04 15:08

个回答

  • 子夜o阳光
    2017-05-11 17:19:33

    var a = pixelData[i*4+2]

    var grey = r*0.3 + g*0.59 + b*0.11

    声明a却用b计算