如何使用canvas.toDataURL()将画布保存为图像?我目前正在构建一个HTML 5 web应用程序/Phonegap本地应用程序,我似乎不知道如何将我的画布保存为canvas.toDataURL()..有人能帮帮我吗?这是密码,怎么了?/我的画布被命名为“canvassionalation”JavaScript:function putImage(){
var canvas1 = document.getElementById("canvasSignature");
if (canvas1.getContext) {
var ctx = canvas1.getContext("2d");
var myImage = canvas1.toDataURL("image/png");
}
var imageElement = document.getElementById("MyPix");
imageElement.src = myImage; }HTML 5:<div id="createPNGButton">
<button onclick="putImage()">Save as Image</button> </div>
3 回答
慕勒3428872
TA贡献1848条经验 获得超6个赞
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); // here is the most important part because if you dont replace you will get a DOM 18 exception.window.location.href=image; // it will save locally
- 3 回答
- 0 关注
- 499 浏览
添加回答
举报
0/150
提交
取消