There is such code:
var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.strokeRect(50, 50, 200, 200); var pix = ctx.getImageData(0,0,600,600); for(var i = 0; i <= pix.data.length; ) { if(pix.data[i] > 0) { pix.data[i] = 133; pix.data[i+1] = 20; pix.data[i+2] = 154; } i = i + 4; } ctx.putImageData(pix,0,0); <canvas width="600" height="600" id='canvas'></canvas> If I choose on the basis of pix.data == 0 , then repaints the contour in an arbitrary color. Why doesn't it work for the area around and inside the square?