HTML 5 Canvas学習ログ(九)
601 ワード
HTML 5 Canvas学習ログ(9)画像画素取得
/* chrome Uncaught SecurityError, firefox getImageData web */canvas.click(function(e){var canvasOffset = canvas.offset();var canvasX = Math.floor(e.pageX-canvasOffset.left);var canvasY = Math.floor(e.pageY-canvasOffset.top);var imageData = context.getImageData(canvasX, canvasY, 1, 1);var pixel = imageData.data;var pixelColor = "rgba("+pixel[0]+", "+pixel[1]+", "+pixel[2]+", "+pixel[3]+")";
$("body").css("backgroundColor", pixelColor);
});