function drawImage(imageObj) { var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); var imageX = 10; var imageY = 6; imageWidth = imageObj.width; imageHeight = imageObj.height; context.drawImage(imageObj, imageX, imageY); var imageData = context.getImageData(imageX, imageY, imageWidth, imageHeight); data = imageData.data; console.log(imageData); // iterate over all pixels for(var i = 0, n = data.length; i < n; i += 4) { console.log("long du tableau : "+data.length); var red = data[i]; var green = data[i + 1]; var blue = data[i + 2]; var alpha = data[i + 3]; console.log(data[10]); } // iterate over all pixels based on x and y coordinates for(var y = 0; y < imageHeight; y++) { // loop through each column for(var x = 0; x < imageWidth; x++) { var red = data[((imageWidth * y) + x) * 4]; var green = data[((imageWidth * y) + x) * 4 + 1]; var blue = data[((imageWidth * y) + x) * 4 + 2]; var alpha = data[((imageWidth * y) + x) * 4 + 3]; console.log('rangée '+y+', colonne '+x+': RGBA = ('+red+','+green+','+blue+','+alpha+')'); } } }