SOLUZIONE tratta da Making and Moving Selectable Shapes on an HTML5 Canvas
codice:
<script src="http://code.jquery.com/jquery-latest.js"></script>
<body style="margin:0;">
<canvas id="canvas" width="400" height="300">This text is displayed if your browser does not support HTML5 Canvas.</canvas><span id="ex"></span>
<script type="text/javascript">
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
ctx.fillStyle = '#FFC02B';
ctx.fillRect(40,40,40,40);
var mx, my;
$(document).ready(function(){
$("#canvas").mousedown(function(e){
mx=e.pageX; my=e.pageY;
var imageData = ctx.getImageData(mx, my, 1, 1);
if (imageData.data[3] > 0) {$("#ex").html("c'è");}
else{$("#ex").html("non c'è");}
$("#ex").append("
R:"+imageData.data[0]+" G:"+imageData.data[1]+" B:"+imageData.data[2]+" A:"+imageData.data[3]);
});
});
</script>
</body>