I'm writing a small demo program to test canvas+ performance. But getImageData(), putImageData() don't seem to work. It leaves a black square on the canvas. Half size in width and height, of course considering the window.devicePixelRatio is 2, something not compatible must exist somewhere. The program works fine in Chrome browser. But won't work using Cocoonjs launcher 2.1.1.
Code:
I 'm using requestAnimationFrame(loop);
ctx.drawImage(origin_img,0,0,410, 180, 0, 0, width, height);
texture = ctx.getImageData(0,0,width,height);
loop{
ctx.clearRect(0,0,ctx.canvas.width,ctx.canvas.height);
ctx.fillStyle = 'red';
ctx.fillRect(0,0,width, height);
ctx.putImageData(texture, 0, 0);
}
The result is: I can see a red rectangle with a 1/4 size black rectangle over it. Can anyone help me with it?
ctx.drawImage() will work in the program.
==============================
Thanks both! I posted my code at
http://spikeyang.boxshell.com/static/js/src.zip
Please click the 3rd link, water_ripple to see the result. Please click top-right button to go back to home page. The main js file is js/demo.js. Main function is waterRippleLoop(). I am trying some water ripple sim code.