Code
Execute
<!DOCTYPE html> <html> <head> <title>wikitechy-HTML Canvas getImageData()</title> </head> <body> <h1>wikitechy-HTML Canvas getImageData() with example: </h1> <canvas id="wikitechyCanvas" width="450" height="200" style="border:1px solid #d3d3d3;"> </canvas> <script> var g = document.getElementById("wikitechyCanvas"); var context = g.getContext("2d"); context.fillStyle = "blue"; context.fillRect(15, 15, 130, 100); function copy() { var imgData = context.getImageData(15, 15, 130, 100); context.putImageData(imgData, 280, 50); } </script> <button onclick="copy()">Copy</button> </body> </html>
Result