Skip to content

Instantly share code, notes, and snippets.

@kkristof
Created June 12, 2014 08:25
Show Gist options
  • Save kkristof/45862b9662ed9f8e9fbc to your computer and use it in GitHub Desktop.
Save kkristof/45862b9662ed9f8e9fbc to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(10,10,50,50);
ctx.fillStyle="blue";
ctx.fillRect(20,20,50,50);
function copy()
{
var imgData=ctx.getImageData(10,10,50,100);
ctx.putImageData(imgData,10,70, 30, 5, 20, 100);
}
</script>
<button onclick="copy()">Copy</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment