I am using the following code
HTML Code for the Canvas and the image
<canvas id="myCanvas" style="display:none" width="400" height="400"></canvas>
<img id="canvasImg" />
JavaScript code for fetching the image from the server and displaying on the canvas followed by displaying the image
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
baseimage = new Image();
baseimage.src = 'what.jpg';
baseimage.onload = function() {
ctx.drawImage(baseimage,1,1);
}
var dataURL = canvas.toDataURL("image/png");
document.getElementById('canvasImg').src = dataURL;
$("#myCanvas").show();
The image is being displayed but without the "what.jpg" file. On the Canvas the file is visiible but in the IMG tag nothing can be seen. I am running this on the latest version of Chrome.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…