Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring HTML5 canvas containing images
    primarykey
    data
    text
    <p>How do you store a canvas that contains images using the toDataURL method? Everything works fine for text and drawing, but I don't know how to handle images. Any help would be appreciated. Thanks</p> <p>I have modified my question as follows: </p> <p>This works when the image is pulled directly from a .png. However, when I call the Google Charts API, toDataURL doesn't work even though the image renders correctly on the canvas. Google Charts is returning a .png. Anyone have any ideas? Thanks.</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;script type="text/javascript" charset="utf-8"&gt; function test() { var c = document.getElementById("drawing-canvas"); var cxt = c.getContext("2d"); // This doesn't work. //var imgsrc = 'http://chart.apis.google.com/chart?cht=tx&amp;chf=bg,s,ffffff&amp;chco=000000&amp; chl=a'; // This works var imgsrc = 'chart.png'; var img = new Image(); img.src = imgsrc; cxt.drawImage(img,0,0); } function wr() { var cc = document.getElementById("drawing-canvas"); var url = cc.toDataURL(); var newImg = document.createElement("img"); newImg.src = url; document.body.appendChild(newImg); } &lt;/script&gt; &lt;/head&gt; &lt;body onload = "test();"&gt; &lt;canvas id="drawing-canvas" width = "500px" height = "500px" style="background-color: #ffffff; border: 2px solid #000000;"&gt; Your browser does not support the canvas element. &lt;/canvas&gt; &lt;input type = "button" value = "go" onclick = "wr();"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload