title: HTML5 canvas toDataURL not working with an image on the canvas
body: <p>What i want to do is to draw an image that I have saved locally onto a canvas. I then want to convert that canvas to a png image. The image loads on the canvas but the png image that I create is blank. Does anyone know how to fix this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
   &lt;head&gt;
  
   &lt;/head&gt;
   &lt;body&gt;
    &lt;img src="" id="canvasImage" /&gt;
    &lt;canvas id="canvasId" width="160" height="145"&gt;&lt;/canvas&gt;
    
    &lt;script&gt;
     
     var canvas = document.getElementById('canvasId');
     var context = canvas.getContext("2d");
     
     image = new Image();
     image.src = "images/rightarrow.png";
     image.onload = function(){
      context.drawImage(image, 0, 0);
     }
     
     var imgTag = canvas.toDataURL("image/png");
     document.getElementById("canvasImage").src = imgTag;
    
    &lt;/script&gt;
    
   &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>