November 2011
Intermediate to advanced
348 pages
7h 2m
English
In this recipe, we'll explore another common pixel manipulation algorithm, converting colors to grayscale.

WARNING: This recipe must be ran on a web server due to security constraints with the getImageData() method.
Follow these steps to convert the colors of an image to grayscale:
window.onload = function(){
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");image object and set the onload property to a function that draws the image and gets the image data: var imageObj = new Image(); imageObj.onload = function(){ var ...Read now
Unlock full access