I suspect the problem is that your image data is probably not ready for what you are trying to use for the canvas. If you put this code aside on onload handlers, this will help (possibly):
var img1 = new Image(), count = 2; img1.src = "cat.jpg"; img1.onload = function() { ctx1.drawImage(img1, 0, 0); checkReadiness(); } var img2 = new Image(); img2.src = "bird.jpg"; img2.onload = function() { ctx2.drawImage(img2, 0, 0); checkReadiness(); } function checkReadiness() { if (--count !== 0) return; for(var x = 0; x<c1.width; x++) {
All I did was add a function wrapper around your code. This function checks the variable of the number of images that I added, and only when it is equal to zero (i.e. only after loading both images), it will do the job.
(This may be superstition, but I always assign an βonloadβ handler before setting the βsrcβ attribute. I have this idea that, perhaps, only in the past, browsers may not start the handler if the image is already in the cache.)
Now one more thing: you probably should just get the image data once, and then iterate over the returned data. Calling "getImageData ()" for each individual pixel will be a great job for the browser.
Pointy
source share