为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用canvas.toDataURL()将画布保存为图像?

如何使用canvas.toDataURL()将画布保存为图像?

慕村225694 2019-10-16 12:09:09
如何使用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



查看完整回答
反对 回复 2019-10-17
  • 3 回答
  • 0 关注
  • 470 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信