var width = 10;
var data = image.data;
var height = 10;
for ( var x = 0; x < width; x++ ) {
for ( var y = 0; y < height; y++ )
var index = 4 * (y * height + x); // 0
var local_variable = ArbitraryClassInstance.getBrightness(x, y); // 0
data[ index ] = ArbitraryClassInstance.getBrightness(x, y); // 0 for both index/call
data[ index + 1 ] = ArbitraryClassInstance.getBrightness(x, y); // 0 for both index/call
}
}
context.putImageData(image, 0, 0);
当我执行代码时 index 和 local_variable 都等于零。Image是一个javascript图像对象,data是图像数据,width和height是图像的尺寸。该类返回亮度。