The CSS border is nudging the whole thing off by 1px. If you want a border, draw it on the canvas :)
var canvas = document.getElementById("mycanvas");
canvas.width = 200;
canvas.height = 50;
canvas.style.position = "absolute";
canvas.style.top = "30px";
canvas.style.left = "100px";
var ctx = canvas.getContext('2d');
ctx.fillStyle = "orange";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fill();
ctx.fillStyle = "red";
ctx.fillRect(0, 0, 20, 20);
ctx.fill();
canvas.addEventListener('click', myfunc, false);
function myfunc(e) {
if (e.layerX <= 20 && e.layerY <= 20) {
var imageData = ctx.getImageData(e.layerX, e.layerY, 1, 1);
alert(imageData.data[0] + " " + imageData.data[1] + " " + imageData.data[2]);
}
}
http://jsfiddle.net/UQM9Q/