Javascript代码:
window.onload = function () {
var canvas=document.getElementById("can");
var img=canvas.toDataURL("image/png");
var button = document.getElementById('saveImage');
img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA'+
'AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO'+
'9TXL0Y4OHwAAAABJRU5ErkJggg==';
button.onclick = function () {
window.location.href = img.replace("image/png", "image/octet-stream");
window.location.href = prev;
};
};
HTML:
<canvas id="can" width="500" height="200"></canvas><br />
<input type="button" value="Done" id="saveImage">
我可以在画布上的 div 上显示图像,但是当我尝试使用上面的 javascript 函数下载它时,它会下载空白图像。我想知道如何从画布上绘制图片。