How to draw a colorpicker on HTML5 canvas?
A basic example would be using getImageData
: http://jsfiddle.net/eGjak/60/.
var ctx = $('#cv').get(0).getContext('2d');
for(var i = 0; i < 30; i++) {
for(var j = 0; j < 30; j++) {
ctx.fillStyle = 'rgb(' +
((i/30*255)|0) + ',' +
((j/30*255)|0) + ',' +
'0)';
ctx.fillRect(i * 10, j * 10, 10, 10);
}
}
$('#cv').click(function(e) {
// get pixel under mouse cursor
var data = ctx.getImageData(e.offsetX, e.offsetY, 1, 1).data;
alert('rgb: ' + [].slice.call(data, 0, 3).join());
});