Resolving Image Saving Issues with canvas.toDataURL()
When attempting to utilize canvas.toURL( ) to tt , you may encounter difficulties. Here's how to approach the situation:
問題與解決方案
// Canvas named "canvasSignature" 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; } HTML5: <div id="createPNGButton"> <button onclick="putImage()">Save as Image</button> </div>
解決方案:
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"); window.location.href = image; // Save locally
程式碼中缺少將影像轉換為二進位流的步驟。修改代碼為:
透過將影像轉換為二進位流並將其視為文件,程式碼可以本地保存該映像。以上是為什麼我的 canvas.toDataURL() 沒有儲存我的圖像?的詳細內容。更多資訊請關注PHP中文網其他相關文章!