如果我理解你需要什么,你基本上想要将图像上的特定颜色变为透明.要做到这一点,你需要使用get
ImageData检查
mdn for an explanation on pixel manipulation.
下面是一些示例代码
var imgd = ctx.getImageData(0,imageWidth,imageHeight),pix = imgd.data;
for (var i = 0,n = pix.length; i
var r = pix[i],g = pix[i+1],b = pix[i+2];
if(g > 150){
// If the green component value is higher than 150
// make the pixel transparent because i+3 is the alpha component
// values 0-255 work,255 is solid
pix[i + 3] = 0;
}
}
ctx.putImageData(imgd,0);
使用上面的代码,您可以使用检查fuschia
if(r == 255&& g == 0&& b == 255)