如何使用canvas.toDataURL()將畫布保存為圖像?我目前正在構(gòu)建一個HTML 5 web應(yīng)用程序/Phonegap本地應(yīng)用程序,我似乎不知道如何將我的畫布保存為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貢獻(xiàn)1848條經(jīng)驗 獲得超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 關(guān)注
- 531 瀏覽
添加回答
舉報
0/150
提交
取消