I have two canvases on the same page, with different ids. I use the first canvas to draw Images and the second is like an album where you can see all of your paintings...... When I use var Img = painter.getImageData(0, 0, 100, 100)
and album.putImageData(Img, 0, 0)
it doesn't work. Plz help!
Code : (there may be some errors, because this is hand written write now, my original code is too long)
HTML :
<html>
<body>
<canvas id="album" width="1000" height="1000"></canvas>
<canvas id="painter" width="100" height="100" onclick="draw(event)"></canvas>
<button onclick="sub()">Submit to album</button>
</body>
</html>
JS :
var album = document.getElementById("ambum").getContext("2d");
var painter = document.getElementById("painter").getContext("2d");
var SRC = "";
function draw(evt) {
var X = evt.clientX;
var Y = evt.clientY;
painter.beginpath();
painter.fillStyle = "red";
painter.fillRect(X - 1000, Y, 100, 100);
}
function sub() {
var SRC = painter.getImageData(1000, 0, 100, 100);
album.beginPath();
album.putImageData(SRC, 0, 0);
}