Skip to content

Instantly share code, notes, and snippets.

@jviereck
Created April 25, 2012 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jviereck/2491890 to your computer and use it in GitHub Desktop.
Save jviereck/2491890 to your computer and use it in GitHub Desktop.
<html>
<body>
<canvas id="canvas" style="border:1px solid black"></canvas>
<img id="image"></img>
<script>
var image = document.getElementById('image');
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.fillStyle = "yellow";
ctx.fillRect(0, 0, 300, 150);
ctx.fillStyle = "black";
ctx.fillRect(50, 50, 200, 50);
// Load the current canvas content in the image.
image.src = canvas.toDataURL("image/jpeg", 1.0);
ctx.fillStyle = "white";
ctx.fillRect(0, 0, 300, 150);
// Draw the image directly again. If the image is loaded, there should
// be something on the canvas :/
ctx.drawImage(image, 10, 10);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment