data = imageData.data;
for (i=0, len=data.length; i < len; i+=4){
red = data[i];
green = data[i+1];
blue = data[i+2];
alpha = data[i+3];
//get the average of rgb
average = Math.floor((red + green + blue) / 3);
//set the colors, leave alpha alone
data[i] = average;
data[i+1] = average;
data[i+2] = average;
}
//assign back to image data and display
imageData.data = data; // 这里的date 从哪里取得
苦逼的代码狗
相关分类